blob: 97ab0c44ccffb6f9b80683cd5c52e4cf1d7bab34 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00007//
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 Hinnant3e519522010-05-11 19:42:16 +000019#include <bitset>
20#include <cassert>
21#include <type_traits>
22
Eric Fiselier78f8ce42016-06-15 01:42:35 +000023#include "test_macros.h"
24
Howard Hinnant3e519522010-05-11 19:42:16 +000025template <std::size_t N>
26void
27test()
28{
29 typedef std::bitset<N> T;
30 typedef std::hash<T> H;
Marshall Clowd95510e2015-01-07 21:53:23 +000031 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 Clow7c803382017-03-23 02:40:28 +000033 ASSERT_NOEXCEPT(H()(T()));
Stephan T. Lavavej6081edc2017-05-04 01:43:58 +000034
Howard Hinnant3e519522010-05-11 19:42:16 +000035 H h;
36 T bs(static_cast<unsigned long long>(N));
Eric Fiselier78f8ce42016-06-15 01:42:35 +000037 const std::size_t result = h(bs);
38 LIBCPP_ASSERT(result == N);
39 ((void)result); // Prevent unused warning
Howard Hinnant3e519522010-05-11 19:42:16 +000040}
41
42int main()
43{
44 test<0>();
45 test<10>();
46 test<100>();
47 test<1000>();
48}