//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // template // struct hash> // { // typedef unique_ptr argument_type; // typedef size_t result_type; // size_t operator()(const unique_ptr& p) const; // }; #include #include #include "test_macros.h" #if TEST_STD_VER >= 11 #include "poisoned_hash_helper.h" #include "deleter_types.h" #include "min_allocator.h" template void test_enabled_with_deleter() { using UPtr = std::unique_ptr; using pointer = typename UPtr::pointer; using RawDel = typename std::decay::type; RawDel d(1); UPtr p(nullptr, std::forward(d)); test_hash_enabled_for_type(p); test_hash_enabled_for_type(); } template void test_disabled_with_deleter() { using UPtr = std::unique_ptr; using pointer = typename UPtr::pointer; test_hash_disabled_for_type(); test_hash_disabled_for_type(); } namespace std { template struct hash<::min_pointer>> { size_t operator()(::min_pointer> p) const TEST_NOEXCEPT_FALSE { if (!p) return 0; return std::hash{}(std::addressof(*p)); } }; } struct A {}; #endif // TEST_STD_VER >= 11 int main(int, char**) { { int* ptr = new int; std::unique_ptr p(ptr); std::hash > f; std::size_t h = f(p); assert(h == std::hash()(ptr)); } #if TEST_STD_VER >= 11 { std::unique_ptr> pThrowingHash; std::hash>> fThrowingHash; ASSERT_NOT_NOEXCEPT(fThrowingHash(pThrowingHash)); } { test_enabled_with_deleter>(); test_enabled_with_deleter>(); test_enabled_with_deleter>(); test_enabled_with_deleter>(); test_enabled_with_deleter&>(); test_enabled_with_deleter&>(); test_enabled_with_deleter const&>(); test_enabled_with_deleter const&>(); } { test_enabled_with_deleter>(); test_enabled_with_deleter>(); test_enabled_with_deleter>(); test_enabled_with_deleter>(); #if TEST_STD_VER > 14 test_disabled_with_deleter>(); test_disabled_with_deleter>(); test_disabled_with_deleter>(); test_disabled_with_deleter>(); #endif } #endif return 0; }