test_hash.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include <boost/config.hpp>
  11. #include <boost/core/lightweight_test.hpp>
  12. #include <boost/uuid/string_generator.hpp>
  13. #include <boost/uuid/uuid.hpp>
  14. #include <boost/uuid/uuid_hash.hpp>
  15. #include <iostream>
  16. #if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
  17. #include <unordered_set>
  18. #endif
  19. int main(int, char*[])
  20. {
  21. #if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
  22. using namespace boost::uuids;
  23. string_generator gen;
  24. uuid u1 = gen("01234567-89AB-CDEF-0123-456789abcdef");
  25. uuid u2 = gen("fedcba98-7654-3210-fedc-ba9876543210");
  26. std::hash<uuid> hasher;
  27. BOOST_TEST(hasher(u1) != hasher(u2));
  28. std::unordered_set<boost::uuids::uuid> uns;
  29. uns.insert(u1);
  30. uns.insert(u2);
  31. BOOST_TEST_EQ(uns.size(), 2);
  32. return boost::report_errors();
  33. #else
  34. std::cout << "test skipped - no library support for std::hash or std::unordered_set" << std::endl;
  35. return 0;
  36. #endif
  37. }