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 <system_error> 19 #include <cassert> 20 #include <type_traits> 21 22 #include "test_macros.h" 23 24 void 25 test(int i) 26 { 27 typedef std::error_code T; 28 typedef std::hash<T> H; 29 static_assert((std::is_same<H::argument_type, T>::value), "" ); 30 static_assert((std::is_same<H::result_type, std::size_t>::value), "" ); 31 ASSERT_NOEXCEPT(H()(T())); 32 H h; 33 T ec(i, std::system_category()); 34 const std::size_t result = h(ec); 35 LIBCPP_ASSERT(result == static_cast<std::size_t>(i)); 36 ((void)result); // Prevent unused warning 37 } 38 39 int main(int, char**) 40 { 41 test(0); 42 test(2); 43 test(10); 44 45 return 0; 46 } 47