15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65a83710eSEric Fiselier // 75a83710eSEric Fiselier //===----------------------------------------------------------------------===// 85a83710eSEric Fiselier 9*dc066888SArthur O'Dwyer // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS 10*dc066888SArthur O'Dwyer 115a83710eSEric Fiselier // <functional> 125a83710eSEric Fiselier 135a83710eSEric Fiselier // template <class T> 145a83710eSEric Fiselier // struct hash 155a83710eSEric Fiselier // : public unary_function<T, size_t> 165a83710eSEric Fiselier // { 175a83710eSEric Fiselier // size_t operator()(T val) const; 185a83710eSEric Fiselier // }; 195a83710eSEric Fiselier 205a83710eSEric Fiselier // Not very portable 215a83710eSEric Fiselier 225a83710eSEric Fiselier #include <functional> 235a83710eSEric Fiselier #include <cassert> 245a83710eSEric Fiselier #include <type_traits> 255a83710eSEric Fiselier #include <limits> 265a83710eSEric Fiselier #include <cmath> 275a83710eSEric Fiselier 287c803385SMarshall Clow #include "test_macros.h" 297c803385SMarshall Clow 305a83710eSEric Fiselier template <class T> 315a83710eSEric Fiselier void test()325a83710eSEric Fiseliertest() 335a83710eSEric Fiselier { 34d95510ebSMarshall Clow typedef std::hash<T> H; 35*dc066888SArthur O'Dwyer #if TEST_STD_VER <= 17 36d95510ebSMarshall Clow static_assert((std::is_same<typename H::argument_type, T>::value), ""); 37d95510ebSMarshall Clow static_assert((std::is_same<typename H::result_type, std::size_t>::value), ""); 38*dc066888SArthur O'Dwyer #endif 397c803385SMarshall Clow ASSERT_NOEXCEPT(H()(T())); 40d95510ebSMarshall Clow H h; 41d95510ebSMarshall Clow 425a83710eSEric Fiselier std::size_t t0 = h(0.); 435a83710eSEric Fiselier std::size_t tn0 = h(-0.); 44b03da3b6SEric Fiselier std::size_t tp1 = h(static_cast<T>(0.1)); 455a83710eSEric Fiselier std::size_t t1 = h(1); 465a83710eSEric Fiselier std::size_t tn1 = h(-1); 475a83710eSEric Fiselier std::size_t pinf = h(INFINITY); 485a83710eSEric Fiselier std::size_t ninf = h(-INFINITY); 495a83710eSEric Fiselier assert(t0 == tn0); 505a83710eSEric Fiselier assert(t0 != tp1); 515a83710eSEric Fiselier assert(t0 != t1); 525a83710eSEric Fiselier assert(t0 != tn1); 535a83710eSEric Fiselier assert(t0 != pinf); 545a83710eSEric Fiselier assert(t0 != ninf); 555a83710eSEric Fiselier 565a83710eSEric Fiselier assert(tp1 != t1); 575a83710eSEric Fiselier assert(tp1 != tn1); 585a83710eSEric Fiselier assert(tp1 != pinf); 595a83710eSEric Fiselier assert(tp1 != ninf); 605a83710eSEric Fiselier 615a83710eSEric Fiselier assert(t1 != tn1); 625a83710eSEric Fiselier assert(t1 != pinf); 635a83710eSEric Fiselier assert(t1 != ninf); 645a83710eSEric Fiselier 655a83710eSEric Fiselier assert(tn1 != pinf); 665a83710eSEric Fiselier assert(tn1 != ninf); 675a83710eSEric Fiselier 685a83710eSEric Fiselier assert(pinf != ninf); 695a83710eSEric Fiselier } 705a83710eSEric Fiselier main(int,char **)712df59c50SJF Bastienint main(int, char**) 725a83710eSEric Fiselier { 735a83710eSEric Fiselier test<float>(); 745a83710eSEric Fiselier test<double>(); 755a83710eSEric Fiselier test<long double>(); 762df59c50SJF Bastien 772df59c50SJF Bastien return 0; 785a83710eSEric Fiselier } 79