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
277c803385SMarshall Clow #include "test_macros.h"
287c803385SMarshall Clow
295a83710eSEric Fiselier template <class T>
305a83710eSEric Fiselier void
test()315a83710eSEric Fiselier test()
325a83710eSEric Fiselier {
33d95510ebSMarshall Clow typedef std::hash<T> H;
34*dc066888SArthur O'Dwyer #if TEST_STD_VER <= 17
35d95510ebSMarshall Clow static_assert((std::is_same<typename H::argument_type, T>::value), "");
36d95510ebSMarshall Clow static_assert((std::is_same<typename H::result_type, std::size_t>::value), "");
37*dc066888SArthur O'Dwyer #endif
387c803385SMarshall Clow ASSERT_NOEXCEPT(H()(T()));
39d95510ebSMarshall Clow H h;
40d95510ebSMarshall Clow
415a83710eSEric Fiselier typedef typename std::remove_pointer<T>::type type;
425a83710eSEric Fiselier type i;
435a83710eSEric Fiselier type j;
445a83710eSEric Fiselier assert(h(&i) != h(&j));
455a83710eSEric Fiselier }
465a83710eSEric Fiselier
479ea675efSStephan T. Lavavej // can't hash nullptr_t until C++17
test_nullptr()487c803385SMarshall Clow void test_nullptr()
497c803385SMarshall Clow {
50d8323168SMarshall Clow #if TEST_STD_VER > 14
517c803385SMarshall Clow typedef std::nullptr_t T;
527c803385SMarshall Clow typedef std::hash<T> H;
53*dc066888SArthur O'Dwyer #if TEST_STD_VER <= 17
547c803385SMarshall Clow static_assert((std::is_same<typename H::argument_type, T>::value), "" );
557c803385SMarshall Clow static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
56*dc066888SArthur O'Dwyer #endif
577c803385SMarshall Clow ASSERT_NOEXCEPT(H()(T()));
58d8323168SMarshall Clow #endif
597c803385SMarshall Clow }
607c803385SMarshall Clow
main(int,char **)612df59c50SJF Bastien int main(int, char**)
625a83710eSEric Fiselier {
635a83710eSEric Fiselier test<int*>();
647c803385SMarshall Clow test_nullptr();
652df59c50SJF Bastien
662df59c50SJF Bastien return 0;
675a83710eSEric Fiselier }
68