1 2 // Copyright 2018 Daniel James 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 6 #include "./config.hpp" 7 8 #ifndef BOOST_HASH_TEST_STD_INCLUDES 9 # include <boost/container_hash/hash.hpp> 10 #endif 11 #include <boost/config.hpp> 12 #include <boost/core/lightweight_test.hpp> 13 14 #if BOOST_HASH_HAS_OPTIONAL 15 16 #include <optional> 17 #include <string> 18 test_optional_int()19void test_optional_int() 20 { 21 std::optional<int> x1a; 22 std::optional<int> x1b; 23 std::optional<int> x2a(10); 24 std::optional<int> x2b(x2a); 25 std::optional<int> x3(20); 26 27 boost::hash<std::optional<int> > hasher; 28 29 BOOST_TEST(hasher(x1a) == hasher(x1a)); 30 BOOST_TEST(hasher(x1a) == hasher(x1b)); 31 BOOST_TEST(hasher(x1a) != hasher(x2a)); 32 BOOST_TEST(hasher(x1a) != hasher(x3)); 33 BOOST_TEST(hasher(x2a) == hasher(x2a)); 34 BOOST_TEST(hasher(x2b) == hasher(x2b)); 35 BOOST_TEST(hasher(x2a) != hasher(x3)); 36 BOOST_TEST(hasher(x3) == hasher(x3)); 37 } 38 test_optional_string()39void test_optional_string() 40 { 41 std::optional<std::string> x1a; 42 std::optional<std::string> x1b; 43 std::optional<std::string> x2a("10"); 44 std::optional<std::string> x2b(x2a); 45 std::optional<std::string> x3("20"); 46 47 boost::hash<std::optional<std::string> > hasher; 48 49 BOOST_TEST(hasher(x1a) == hasher(x1a)); 50 BOOST_TEST(hasher(x1a) == hasher(x1b)); 51 BOOST_TEST(hasher(x1a) != hasher(x2a)); 52 BOOST_TEST(hasher(x1a) != hasher(x3)); 53 BOOST_TEST(hasher(x2a) == hasher(x2a)); 54 BOOST_TEST(hasher(x2b) == hasher(x2b)); 55 BOOST_TEST(hasher(x2a) != hasher(x3)); 56 BOOST_TEST(hasher(x3) == hasher(x3)); 57 } 58 59 #endif 60 main()61int main() 62 { 63 #if BOOST_HASH_HAS_OPTIONAL 64 test_optional_int(); 65 test_optional_string(); 66 #else 67 BOOST_LIGHTWEIGHT_TEST_OSTREAM << "<optional> not available." << std::endl; 68 #endif 69 return boost::report_errors(); 70 } 71