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/config.hpp>
12#include <boost/config/pragma_message.hpp>
13
14#if defined(BOOST_NO_CXX11_HDR_UNORDERED_SET)
15
16BOOST_PRAGMA_MESSAGE( "Test skipped, BOOST_NO_CXX11_HDR_UNORDERED_SET is defined" )
17int main() {}
18
19#elif defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && defined(_CPPLIB_VER) && _CPPLIB_VER >= 520
20
21BOOST_PRAGMA_MESSAGE( "Test skipped, _CPPLIB_VER >= 520 and BOOST_NO_CXX11_VARIADIC_TEMPLATES is defined" )
22int main() {}
23
24#else
25
26#include <unordered_set>
27
28template<class T> void test()
29{
30 typedef std::unordered_multiset<T> set;
31 typedef boost::hash<set> hash;
32
33 int const N = 32;
34
35 std::size_t h[ N ];
36
37 set v;
38
39 for( int i = 0; i < N; ++i )
40 {
41 h[ i ] = hash()( v );
42
43 BOOST_TEST_EQ( h[ i ], hash()( v ) );
44
45 for( int j = 0; j < i; ++j )
46 {
47 BOOST_TEST_NE( h[ j ], h[ i ] );
48 }
49
50 v.insert( T() );
51 }
52}
53
54int main()
55{
56 test<int>();
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_multiset_test.cpp