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