xref: /llvm-project/libcxx/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp (revision 681cde7dd8b5613dbafc9ca54e0288477f946be3)
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <functional>
10 
11 // template <class T>
12 // struct hash
13 // {
14 //     size_t operator()(T val) const;
15 // };
16 
17 #include <bitset>
18 #include <cassert>
19 #include <type_traits>
20 
21 #include "test_macros.h"
22 
23 template <std::size_t N>
24 void
test()25 test()
26 {
27     typedef std::bitset<N> T;
28     typedef std::hash<T> H;
29 #if TEST_STD_VER <= 14
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), "" );
32 #endif
33     ASSERT_NOEXCEPT(H()(T()));
34 
35     H h;
36     T bs(static_cast<unsigned long long>(N));
37     const std::size_t result = h(bs);
38     LIBCPP_ASSERT(result == N);
39     ((void)result); // Prevent unused warning
40 }
41 
main(int,char **)42 int main(int, char**)
43 {
44     test<0>();
45     test<10>();
46     test<100>();
47     test<1000>();
48 
49   return 0;
50 }
51