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 
95a83710eSEric Fiselier // <functional>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // template <class T>
125a83710eSEric Fiselier // struct hash
135a83710eSEric Fiselier // {
145a83710eSEric Fiselier //     size_t operator()(T val) const;
155a83710eSEric Fiselier // };
165a83710eSEric Fiselier 
175a83710eSEric Fiselier #include <bitset>
185a83710eSEric Fiselier #include <cassert>
195a83710eSEric Fiselier #include <type_traits>
205a83710eSEric Fiselier 
2178f8ce48SEric Fiselier #include "test_macros.h"
2278f8ce48SEric Fiselier 
235a83710eSEric Fiselier template <std::size_t N>
245a83710eSEric Fiselier void
test()255a83710eSEric Fiselier test()
265a83710eSEric Fiselier {
275a83710eSEric Fiselier     typedef std::bitset<N> T;
285a83710eSEric Fiselier     typedef std::hash<T> H;
29*681cde7dSNikolas Klauser #if TEST_STD_VER <= 14
30d95510ebSMarshall Clow     static_assert((std::is_same<typename H::argument_type, T>::value), "" );
31d95510ebSMarshall Clow     static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
32*681cde7dSNikolas Klauser #endif
337c803385SMarshall Clow     ASSERT_NOEXCEPT(H()(T()));
347c803385SMarshall Clow 
355a83710eSEric Fiselier     H h;
365a83710eSEric Fiselier     T bs(static_cast<unsigned long long>(N));
3778f8ce48SEric Fiselier     const std::size_t result = h(bs);
3878f8ce48SEric Fiselier     LIBCPP_ASSERT(result == N);
3978f8ce48SEric Fiselier     ((void)result); // Prevent unused warning
405a83710eSEric Fiselier }
415a83710eSEric Fiselier 
main(int,char **)422df59c50SJF Bastien int main(int, char**)
435a83710eSEric Fiselier {
445a83710eSEric Fiselier     test<0>();
455a83710eSEric Fiselier     test<10>();
465a83710eSEric Fiselier     test<100>();
475a83710eSEric Fiselier     test<1000>();
482df59c50SJF Bastien 
492df59c50SJF Bastien   return 0;
505a83710eSEric Fiselier }
51