hash.pass.cpp revision 01afa5c6e407e985d9643707d7b7ab1384bd9317
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <optional> 11 12// template <class T> struct hash<optional<T>>; 13 14#include <optional> 15#include <string> 16#include <memory> 17#include <cassert> 18 19#if _LIBCPP_STD_VER > 11 20 21#endif // _LIBCPP_STD_VER > 11 22 23int main() 24{ 25#if _LIBCPP_STD_VER > 11 26 { 27 typedef int T; 28 std::optional<T> opt; 29 assert(std::hash<std::optional<T>>{}(opt) == 0); 30 opt = 2; 31 assert(std::hash<std::optional<T>>{}(opt) == std::hash<T>{}(*opt)); 32 } 33 { 34 typedef std::string T; 35 std::optional<T> opt; 36 assert(std::hash<std::optional<T>>{}(opt) == 0); 37 opt = std::string("123"); 38 assert(std::hash<std::optional<T>>{}(opt) == std::hash<T>{}(*opt)); 39 } 40 { 41 typedef std::unique_ptr<int> T; 42 std::optional<T> opt; 43 assert(std::hash<std::optional<T>>{}(opt) == 0); 44 opt = std::unique_ptr<int>(new int(3)); 45 assert(std::hash<std::optional<T>>{}(opt) == std::hash<T>{}(*opt)); 46 } 47#endif // _LIBCPP_STD_VER > 11 48} 49