• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
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 
19 #include <bitset>
20 #include <cassert>
21 #include <type_traits>
22 
23 #include "test_macros.h"
24 
25 template <std::size_t N>
26 void
test()27 test()
28 {
29     typedef std::bitset<N> T;
30     typedef std::hash<T> H;
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), "" );
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()42 int main()
43 {
44     test<0>();
45     test<10>();
46     test<100>();
47     test<1000>();
48 }
49