Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <functional> |
| 10 | |
| 11 | // template <class T> |
| 12 | // struct hash |
| 13 | // : public unary_function<T, size_t> |
| 14 | // { |
| 15 | // size_t operator()(T val) const; |
| 16 | // }; |
| 17 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | #include <bitset> |
| 19 | #include <cassert> |
| 20 | #include <type_traits> |
| 21 | |
Eric Fiselier | 78f8ce4 | 2016-06-15 01:42:35 +0000 | [diff] [blame] | 22 | #include "test_macros.h" |
| 23 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | template <std::size_t N> |
| 25 | void |
| 26 | test() |
| 27 | { |
| 28 | typedef std::bitset<N> T; |
| 29 | typedef std::hash<T> H; |
Marshall Clow | d95510e | 2015-01-07 21:53:23 +0000 | [diff] [blame] | 30 | static_assert((std::is_same<typename H::argument_type, T>::value), "" ); |
| 31 | 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] | 32 | ASSERT_NOEXCEPT(H()(T())); |
Stephan T. Lavavej | 6081edc | 2017-05-04 01:43:58 +0000 | [diff] [blame] | 33 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | H h; |
| 35 | T bs(static_cast<unsigned long long>(N)); |
Eric Fiselier | 78f8ce4 | 2016-06-15 01:42:35 +0000 | [diff] [blame] | 36 | const std::size_t result = h(bs); |
| 37 | LIBCPP_ASSERT(result == N); |
| 38 | ((void)result); // Prevent unused warning |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | } |
| 40 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 41 | int main(int, char**) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | { |
| 43 | test<0>(); |
| 44 | test<10>(); |
| 45 | test<100>(); |
| 46 | test<1000>(); |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 47 | |
| 48 | return 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | } |