blob: ca23d78c531df07cfc1906dab4801d7157c135b7 [file] [log] [blame]
Howard Hinnante7d746d2013-09-02 20:30:37 +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// <optional>
11
12// template <class T> struct hash<optional<T>>;
13
Marshall Clowdfdac032013-11-15 22:42:10 +000014#include <experimental/optional>
Howard Hinnante7d746d2013-09-02 20:30:37 +000015#include <string>
16#include <memory>
17#include <cassert>
18
Howard Hinnante7d746d2013-09-02 20:30:37 +000019
20int main()
21{
22#if _LIBCPP_STD_VER > 11
Marshall Clowdfdac032013-11-15 22:42:10 +000023 using std::experimental::optional;
24
Howard Hinnante7d746d2013-09-02 20:30:37 +000025 {
26 typedef int T;
Marshall Clowdfdac032013-11-15 22:42:10 +000027 optional<T> opt;
28 assert(std::hash<optional<T>>{}(opt) == 0);
Howard Hinnante7d746d2013-09-02 20:30:37 +000029 opt = 2;
Marshall Clowdfdac032013-11-15 22:42:10 +000030 assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
Howard Hinnante7d746d2013-09-02 20:30:37 +000031 }
32 {
33 typedef std::string T;
Marshall Clowdfdac032013-11-15 22:42:10 +000034 optional<T> opt;
35 assert(std::hash<optional<T>>{}(opt) == 0);
Howard Hinnante7d746d2013-09-02 20:30:37 +000036 opt = std::string("123");
Marshall Clowdfdac032013-11-15 22:42:10 +000037 assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
Howard Hinnante7d746d2013-09-02 20:30:37 +000038 }
39 {
40 typedef std::unique_ptr<int> T;
Marshall Clowdfdac032013-11-15 22:42:10 +000041 optional<T> opt;
42 assert(std::hash<optional<T>>{}(opt) == 0);
Howard Hinnante7d746d2013-09-02 20:30:37 +000043 opt = std::unique_ptr<int>(new int(3));
Marshall Clowdfdac032013-11-15 22:42:10 +000044 assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
Howard Hinnante7d746d2013-09-02 20:30:37 +000045 }
46#endif // _LIBCPP_STD_VER > 11
47}