blob: dfac9d94af7c72c36b4909b1be2e744714e4b200 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Hinnant3e519522010-05-11 19:42:16 +00006//
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 Hinnant3e519522010-05-11 19:42:16 +000018#include <bitset>
19#include <cassert>
20#include <type_traits>
21
Eric Fiselier78f8ce42016-06-15 01:42:35 +000022#include "test_macros.h"
23
Howard Hinnant3e519522010-05-11 19:42:16 +000024template <std::size_t N>
25void
26test()
27{
28 typedef std::bitset<N> T;
29 typedef std::hash<T> H;
Marshall Clowd95510e2015-01-07 21:53:23 +000030 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 Clow7c803382017-03-23 02:40:28 +000032 ASSERT_NOEXCEPT(H()(T()));
Stephan T. Lavavej6081edc2017-05-04 01:43:58 +000033
Howard Hinnant3e519522010-05-11 19:42:16 +000034 H h;
35 T bs(static_cast<unsigned long long>(N));
Eric Fiselier78f8ce42016-06-15 01:42:35 +000036 const std::size_t result = h(bs);
37 LIBCPP_ASSERT(result == N);
38 ((void)result); // Prevent unused warning
Howard Hinnant3e519522010-05-11 19:42:16 +000039}
40
JF Bastien2df59c52019-02-04 20:31:13 +000041int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000042{
43 test<0>();
44 test<10>();
45 test<100>();
46 test<1000>();
JF Bastien2df59c52019-02-04 20:31:13 +000047
48 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000049}