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 // : public unary_function<T, size_t> 14 // { 15 // size_t operator()(T val) const; 16 // }; 17 18 #include <bitset> 19 #include <cassert> 20 #include <type_traits> 21 22 #include "test_macros.h" 23 24 template <std::size_t N> 25 void 26 test() 27 { 28 typedef std::bitset<N> T; 29 typedef std::hash<T> H; 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 ASSERT_NOEXCEPT(H()(T())); 33 34 H h; 35 T bs(static_cast<unsigned long long>(N)); 36 const std::size_t result = h(bs); 37 LIBCPP_ASSERT(result == N); 38 ((void)result); // Prevent unused warning 39 } 40 41 int main(int, char**) 42 { 43 test<0>(); 44 test<10>(); 45 test<100>(); 46 test<1000>(); 47 48 return 0; 49 } 50