| 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 <set> |
| 12 | |
| 13 | template<class T> void test() |
| 14 | { |
| 15 | typedef std::multiset<T> set; |
| 16 | typedef boost::hash<set> hash; |
| 17 | |
| 18 | int const N = 32; |
| 19 | |
| 20 | std::size_t h[ N ]; |
| 21 | |
| 22 | set v; |
| 23 | |
| 24 | for( int i = 0; i < N; ++i ) |
| 25 | { |
| 26 | h[ i ] = hash()( v ); |
| 27 | |
| 28 | BOOST_TEST_EQ( h[ i ], hash()( v ) ); |
| 29 | |
| 30 | for( int j = 0; j < i; ++j ) |
| 31 | { |
| 32 | BOOST_TEST_NE( h[ j ], h[ i ] ); |
| 33 | } |
| 34 | |
| 35 | v.insert( T() ); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | int main() |
| 40 | { |
| 41 | test<int>(); |
| 42 | test<float>(); |
| 43 | test<double>(); |
| 44 | |
| 45 | return boost::report_errors(); |
| 46 | } |
| 47 |
