| 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 | // <system_error> |
| 10 | // |
| 11 | // template <> |
| 12 | // struct hash<error_condition>; |
| 13 | |
| 14 | #include <system_error> |
| 15 | #include <cassert> |
| 16 | #include <cstddef> |
| 17 | #include <functional> |
| 18 | #include <type_traits> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | |
| 22 | void |
| 23 | test(int i) |
| 24 | { |
| 25 | typedef std::error_condition T; |
| 26 | typedef std::hash<T> H; |
| 27 | #if TEST_STD_VER <= 14 |
| 28 | static_assert((std::is_same<H::argument_type, T>::value), "" ); |
| 29 | static_assert((std::is_same<H::result_type, std::size_t>::value), "" ); |
| 30 | #endif |
| 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(i: 0); |
| 42 | test(i: 2); |
| 43 | test(i: 10); |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |