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 // {
14 //     size_t operator()(T val) const;
15 // };
16 
17 #include <system_error>
18 #include <cassert>
19 #include <type_traits>
20 
21 #include "test_macros.h"
22 
23 void
24 test(int i)
25 {
26     typedef std::error_code T;
27     typedef std::hash<T> H;
28 #if TEST_STD_VER <= 14
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 #endif
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 
40 int main(int, char**)
41 {
42     test(0);
43     test(2);
44     test(10);
45 
46   return 0;
47 }
48