//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11, c++14 // // template struct hash>; #include #include #include #include #include "poisoned_hash_helper.hpp" struct A {}; struct B {}; namespace std { template <> struct hash { size_t operator()(B const&) TEST_NOEXCEPT_FALSE { return 0; } }; } int main() { 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>(); } }