55 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <functional>10 11// template <class T>12// struct hash13// {14// size_t operator()(T val) const;15// };16 17// Not very portable18 19#include <string>20#include <cassert>21#include <type_traits>22 23#include "test_macros.h"24 25template <class T>26void test() {27 typedef std::hash<T> H;28#if TEST_STD_VER <= 1429 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#endif32 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 42int main(int, char**) {43 test<std::string>();44#ifndef TEST_HAS_NO_CHAR8_T45 test<std::u8string>();46#endif47 test<std::u16string>();48 test<std::u32string>();49#ifndef TEST_HAS_NO_WIDE_CHARACTERS50 test<std::wstring>();51#endif52 53 return 0;54}55