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_SET)
16
17BOOST_PRAGMA_MESSAGE( "Test skipped, BOOST_NO_CXX11_HDR_UNORDERED_SET 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_set>
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_set<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 v.insert( static_cast<T>( rng() ) );
48 }
49}
50
51int main()
52{
53 test<unsigned>();
54 test<boost::uint64_t>();
55 test<float>();
56 test<double>();
57
58 return boost::report_errors();
59}
60
61#endif
62

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