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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <functional>
10
11// template <class T>
12// struct hash
13// {
14// size_t operator()(T val) const;
15// };
16
17#include <vector>
18#include <cassert>
19#include <iterator>
20#include <type_traits>
21
22#include "test_macros.h"
23#include "min_allocator.h"
24
25template <class VB>
26TEST_CONSTEXPR_CXX20 void test() {
27 typedef std::hash<VB> H;
28#if TEST_STD_VER <= 14
29 static_assert((std::is_same<typename H::argument_type, VB>::value), "");
30 static_assert((std::is_same<typename H::result_type, std::size_t>::value), "");
31#endif
32 ASSERT_NOEXCEPT(H()(VB()));
33
34 bool ba[] = {true, false, true, true, false};
35 VB vb(std::begin(arr&: ba), std::end(arr&: ba));
36 H h;
37 if (!TEST_IS_CONSTANT_EVALUATED) {
38 const std::size_t hash_value = h(vb);
39 assert(h(vb) == hash_value);
40 LIBCPP_ASSERT(hash_value != 0);
41 }
42}
43
44TEST_CONSTEXPR_CXX20 bool tests() {
45 test<std::vector<bool> >();
46#if TEST_STD_VER >= 11
47 test<std::vector<bool, min_allocator<bool>>>();
48#endif
49
50 return true;
51}
52
53int main(int, char**) {
54 tests();
55#if TEST_STD_VER > 17
56 static_assert(tests());
57#endif
58 return 0;
59}
60

source code of libcxx/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp