Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <functional> |
| 11 | |
| 12 | // template <class T> |
| 13 | // struct hash |
| 14 | // : public unary_function<T, size_t> |
| 15 | // { |
| 16 | // size_t operator()(T val) const; |
| 17 | // }; |
| 18 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | #include <bitset> |
| 20 | #include <cassert> |
| 21 | #include <type_traits> |
| 22 | |
Eric Fiselier | 78f8ce4 | 2016-06-15 01:42:35 +0000 | [diff] [blame] | 23 | #include "test_macros.h" |
| 24 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | template <std::size_t N> |
| 26 | void |
| 27 | test() |
| 28 | { |
| 29 | typedef std::bitset<N> T; |
| 30 | typedef std::hash<T> H; |
Marshall Clow | d95510e | 2015-01-07 21:53:23 +0000 | [diff] [blame] | 31 | static_assert((std::is_same<typename H::argument_type, T>::value), "" ); |
| 32 | static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); |
Marshall Clow | 7c80338 | 2017-03-23 02:40:28 +0000 | [diff] [blame] | 33 | ASSERT_NOEXCEPT(H()(T())); |
Stephan T. Lavavej | 6081edc | 2017-05-04 01:43:58 +0000 | [diff] [blame] | 34 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | H h; |
| 36 | T bs(static_cast<unsigned long long>(N)); |
Eric Fiselier | 78f8ce4 | 2016-06-15 01:42:35 +0000 | [diff] [blame] | 37 | const std::size_t result = h(bs); |
| 38 | LIBCPP_ASSERT(result == N); |
| 39 | ((void)result); // Prevent unused warning |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | int main() |
| 43 | { |
| 44 | test<0>(); |
| 45 | test<10>(); |
| 46 | test<100>(); |
| 47 | test<1000>(); |
| 48 | } |