blob: dfdd07ddf452e30ececcdce7a25fe965e6ed5ea5 [file] [log] [blame]
Eric Fiseliera9e65962016-10-12 07:46:20 +00001//===----------------------------------------------------------------------===//
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// UNSUPPORTED: c++98, c++03, c++11, c++14
11// <optional>
12
13// template <class T> struct hash<optional<T>>;
14
15#include <optional>
16#include <string>
17#include <memory>
18#include <cassert>
19
20
21int main()
22{
23 using std::optional;
24 const std::size_t nullopt_hash =
25 std::hash<optional<double>>{}(optional<double>{});
26
27 {
28 typedef int T;
29 optional<T> opt;
30 assert(std::hash<optional<T>>{}(opt) == nullopt_hash);
31 opt = 2;
32 assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
33 }
34 {
35 typedef std::string T;
36 optional<T> opt;
37 assert(std::hash<optional<T>>{}(opt) == nullopt_hash);
38 opt = std::string("123");
39 assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
40 }
41 {
42 typedef std::unique_ptr<int> T;
43 optional<T> opt;
44 assert(std::hash<optional<T>>{}(opt) == nullopt_hash);
45 opt = std::unique_ptr<int>(new int(3));
46 assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
47 }
48}