| 1 | // Copyright 2022 Peter Dimov. |
|---|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #include <boost/container_hash/hash.hpp> |
| 6 | #include <boost/core/lightweight_test.hpp> |
| 7 | #include <boost/config.hpp> |
| 8 | #include <vector> |
| 9 | #include <deque> |
| 10 | #include <list> |
| 11 | #if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST) |
| 12 | # include <forward_list> |
| 13 | #endif |
| 14 | |
| 15 | template<class T> std::size_t hv( T const& t ) |
| 16 | { |
| 17 | return boost::hash<T>()( t ); |
| 18 | } |
| 19 | |
| 20 | template<class T> void test() |
| 21 | { |
| 22 | for( std::size_t i = 0; i < 8; ++i ) |
| 23 | { |
| 24 | std::vector<T> v( i ); |
| 25 | std::size_t h0 = hv( v ); |
| 26 | |
| 27 | std::deque<T> d( v.begin(), v.end() ); |
| 28 | BOOST_TEST_EQ( h0, hv( d ) ); |
| 29 | |
| 30 | std::list<T> l( v.begin(), v.end() ); |
| 31 | BOOST_TEST_EQ( h0, hv( l ) ); |
| 32 | |
| 33 | #if !defined(BOOST_NO_CXX11_HDR_FORWARD_LIST) |
| 34 | |
| 35 | std::forward_list<T> f( v.begin(), v.end() ); |
| 36 | BOOST_TEST_EQ( h0, hv( f ) ); |
| 37 | |
| 38 | #endif |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | int main() |
| 43 | { |
| 44 | test<char>(); |
| 45 | test<unsigned char>(); |
| 46 | test<signed char>(); |
| 47 | test<int>(); |
| 48 | test<float>(); |
| 49 | test<double>(); |
| 50 | |
| 51 | #if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L |
| 52 | test<char8_t>(); |
| 53 | #endif |
| 54 | |
| 55 | #if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L |
| 56 | test<std::byte>(); |
| 57 | #endif |
| 58 | |
| 59 | return boost::report_errors(); |
| 60 | } |
| 61 |
