60 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// <functional>10 11// template <class T>12// struct hash13// {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 <= 1429 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#endif32 ASSERT_NOEXCEPT(H()(VB()));33 34 bool ba[] = {true, false, true, true, false};35 VB vb(std::begin(ba), std::end(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 >= 1147 test<std::vector<bool, min_allocator<bool>>>();48#endif49 50 return true;51}52 53int main(int, char**) {54 tests();55#if TEST_STD_VER > 1756 static_assert(tests());57#endif58 return 0;59}60