| 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 | // Not very portable |
| 18 | |
| 19 | #include <string> |
| 20 | #include <cassert> |
| 21 | #include <type_traits> |
| 22 | |
| 23 | #include "test_macros.h" |
| 24 | |
| 25 | template <class T> |
| 26 | void test() { |
| 27 | typedef std::hash<T> H; |
| 28 | #if TEST_STD_VER <= 14 |
| 29 | static_assert((std::is_same<typename H::argument_type, T>::value), "" ); |
| 30 | static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); |
| 31 | #endif |
| 32 | ASSERT_NOEXCEPT(H()(T())); |
| 33 | |
| 34 | H h; |
| 35 | std::string g1 = "1234567890" ; |
| 36 | std::string g2 = "1234567891" ; |
| 37 | T s1(g1.begin(), g1.end()); |
| 38 | T s2(g2.begin(), g2.end()); |
| 39 | assert(h(s1) != h(s2)); |
| 40 | } |
| 41 | |
| 42 | int main(int, char**) { |
| 43 | test<std::string>(); |
| 44 | #ifndef TEST_HAS_NO_CHAR8_T |
| 45 | test<std::u8string>(); |
| 46 | #endif |
| 47 | test<std::u16string>(); |
| 48 | test<std::u32string>(); |
| 49 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 50 | test<std::wstring>(); |
| 51 | #endif |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |