//===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14 // // template struct hash>; #include #include #include #include #include "poisoned_hash_helper.h" #include "test_macros.h" struct A {}; struct B {}; namespace std { template <> struct hash { size_t operator()(B const&) TEST_NOEXCEPT_FALSE { return 0; } }; } int main(int, char**) { using std::optional; const std::size_t nullopt_hash = std::hash>{}(optional{}); { optional opt; ASSERT_NOT_NOEXCEPT(std::hash>()(opt)); ASSERT_NOT_NOEXCEPT(std::hash>()(opt)); } { typedef int T; optional opt; assert(std::hash>{}(opt) == nullopt_hash); opt = 2; assert(std::hash>{}(opt) == std::hash{}(*opt)); } { typedef std::string T; optional opt; assert(std::hash>{}(opt) == nullopt_hash); opt = std::string("123"); assert(std::hash>{}(opt) == std::hash{}(*opt)); } { typedef std::unique_ptr T; optional opt; assert(std::hash>{}(opt) == nullopt_hash); opt = std::unique_ptr(new int(3)); assert(std::hash>{}(opt) == std::hash{}(*opt)); } { test_hash_enabled_for_type >(); test_hash_enabled_for_type >(); test_hash_enabled_for_type >(); test_hash_enabled_for_type >(); test_hash_disabled_for_type>(); test_hash_disabled_for_type>(); test_hash_enabled_for_type>(); test_hash_enabled_for_type>(); } return 0; }