66 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// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS10 11// <functional>12 13// template <class T>14// struct hash15// : public unary_function<T, size_t>16// {17// size_t operator()(T val) const;18// };19 20// XFAIL: FROZEN-CXX03-HEADERS-FIXME21 22// Not very portable23 24#include <cassert>25#include <cstddef>26#include <functional>27#include <type_traits>28 29#include "test_macros.h"30 31template <class T>32void33test()34{35 typedef std::hash<T> H;36#if TEST_STD_VER <= 1737 static_assert((std::is_same<typename H::argument_type, T>::value), "");38 static_assert((std::is_same<typename H::result_type, std::size_t>::value), "");39#endif40 ASSERT_NOEXCEPT(H()(T()));41 H h;42 43 typedef typename std::remove_pointer<T>::type type;44 type i;45 type j;46 assert(h(&i) != h(&j));47}48 49void test_nullptr() {50 typedef std::nullptr_t T;51 typedef std::hash<T> H;52#if TEST_STD_VER <= 1753 static_assert((std::is_same<typename H::argument_type, T>::value), "");54 static_assert((std::is_same<typename H::result_type, std::size_t>::value), "");55#endif56 ASSERT_NOEXCEPT(H()(T()));57}58 59int main(int, char**)60{61 test<int*>();62 test_nullptr();63 64 return 0;65}66