1 | // |
---|---|
2 | // Copyright (c) 2018 James E. King III |
3 | // |
4 | // Distributed under the Boost Software License, Version 1.0. |
5 | // (See accompanying file LICENSE_1_0.txt or copy at |
6 | // https://www.boost.org/LICENSE_1_0.txt) |
7 | // |
8 | // std::hash support for uuid |
9 | // |
10 | |
11 | #include <boost/config.hpp> |
12 | #include <boost/core/lightweight_test.hpp> |
13 | #include <boost/uuid/string_generator.hpp> |
14 | #include <boost/uuid/uuid.hpp> |
15 | #include <boost/uuid/uuid_hash.hpp> |
16 | #include <iostream> |
17 | |
18 | #if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) |
19 | #include <unordered_set> |
20 | #endif |
21 | |
22 | int main(int, char*[]) |
23 | { |
24 | #if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) |
25 | using namespace boost::uuids; |
26 | string_generator gen; |
27 | |
28 | uuid u1 = gen("01234567-89AB-CDEF-0123-456789abcdef"); |
29 | uuid u2 = gen("fedcba98-7654-3210-fedc-ba9876543210"); |
30 | |
31 | std::hash<uuid> hasher; |
32 | BOOST_TEST(hasher(u1) != hasher(u2)); |
33 | |
34 | std::unordered_set<boost::uuids::uuid> uns; |
35 | uns.insert(x: u1); |
36 | uns.insert(x: u2); |
37 | |
38 | BOOST_TEST_EQ(uns.size(), 2); |
39 | |
40 | return boost::report_errors(); |
41 | #else |
42 | std::cout << "test skipped - no library support for std::hash or std::unordered_set"<< std::endl; |
43 | return 0; |
44 | #endif |
45 | } |
46 |