1// Copyright 2021, 2022 Peter Dimov.
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#if defined(__GNUC__) && __GNUC__ == 8
6# pragma GCC diagnostic ignored "-Wsign-conversion"
7#endif
8
9#include <boost/container_hash/hash.hpp>
10#include <boost/core/lightweight_test.hpp>
11#include <boost/core/detail/splitmix64.hpp>
12#include <boost/config.hpp>
13#include <boost/config/pragma_message.hpp>
14
15#if defined(BOOST_NO_CXX11_HDR_UNORDERED_MAP)
16
17BOOST_PRAGMA_MESSAGE( "Test skipped, BOOST_NO_CXX11_HDR_UNORDERED_MAP is defined" )
18int main() {}
19
20#elif defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && defined(_CPPLIB_VER) && _CPPLIB_VER >= 520
21
22BOOST_PRAGMA_MESSAGE( "Test skipped, _CPPLIB_VER >= 520 and BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined" )
23int main() {}
24
25#else
26
27#include <unordered_map>
28
29template<class T> std::size_t hv( T const& x )
30{
31 return boost::hash<T>()( x );
32}
33
34template<class T> void test()
35{
36 typedef std::unordered_map<T, T> set;
37
38 int const N = 256;
39
40 set v;
41
42 boost::detail::splitmix64 rng;
43
44 for( int i = 0; i < N; ++i )
45 {
46 BOOST_TEST_EQ( hv( v ), boost::hash_unordered_range( v.begin(), v.end() ) );
47
48 T x = static_cast<T>( rng() );
49 v.insert( std::pair<T const, T>( x, x ) );
50 }
51}
52
53int main()
54{
55 test<unsigned>();
56 test<boost::uint64_t>();
57 test<float>();
58 test<double>();
59
60 return boost::report_errors();
61}
62
63#endif
64

source code of boost/libs/container_hash/test/hash_unordered_map_test.cpp