| 1 | // Copyright 2021 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_FORWARD_LIST) |
| 15 | |
| 16 | BOOST_PRAGMA_MESSAGE( "Test skipped, BOOST_NO_CXX11_HDR_FORWARD_LIST is defined") |
| 17 | int main() {} |
| 18 | |
| 19 | #else |
| 20 | |
| 21 | #include <forward_list> |
| 22 | |
| 23 | template<class T> void test() |
| 24 | { |
| 25 | typedef std::forward_list<T> list; |
| 26 | typedef boost::hash<list> hash; |
| 27 | |
| 28 | int const N = 32; |
| 29 | |
| 30 | std::size_t h[ N ]; |
| 31 | |
| 32 | list v; |
| 33 | |
| 34 | for( int i = 0; i < N; ++i ) |
| 35 | { |
| 36 | h[ i ] = hash()( v ); |
| 37 | |
| 38 | BOOST_TEST_EQ( h[ i ], hash()( v ) ); |
| 39 | |
| 40 | for( int j = 0; j < i; ++j ) |
| 41 | { |
| 42 | BOOST_TEST_NE( h[ j ], h[ i ] ); |
| 43 | } |
| 44 | |
| 45 | v.push_front( T() ); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | int main() |
| 50 | { |
| 51 | test<int>(); |
| 52 | test<float>(); |
| 53 | test<double>(); |
| 54 | test< std::forward_list<int> >(); |
| 55 | |
| 56 | return boost::report_errors(); |
| 57 | } |
| 58 | |
| 59 | #endif |
| 60 |
