Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 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 | |
Marshall Clow | dfdac03 | 2013-11-15 22:42:10 +0000 | [diff] [blame] | 14 | #include <experimental/optional> |
Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <memory> |
| 17 | #include <cassert> |
| 18 | |
Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 19 | |
| 20 | int main() |
| 21 | { |
| 22 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | dfdac03 | 2013-11-15 22:42:10 +0000 | [diff] [blame] | 23 | using std::experimental::optional; |
| 24 | |
Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 25 | { |
| 26 | typedef int T; |
Marshall Clow | dfdac03 | 2013-11-15 22:42:10 +0000 | [diff] [blame] | 27 | optional<T> opt; |
| 28 | assert(std::hash<optional<T>>{}(opt) == 0); |
Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 29 | opt = 2; |
Marshall Clow | dfdac03 | 2013-11-15 22:42:10 +0000 | [diff] [blame] | 30 | assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt)); |
Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 31 | } |
| 32 | { |
| 33 | typedef std::string T; |
Marshall Clow | dfdac03 | 2013-11-15 22:42:10 +0000 | [diff] [blame] | 34 | optional<T> opt; |
| 35 | assert(std::hash<optional<T>>{}(opt) == 0); |
Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 36 | opt = std::string("123"); |
Marshall Clow | dfdac03 | 2013-11-15 22:42:10 +0000 | [diff] [blame] | 37 | assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt)); |
Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 38 | } |
| 39 | { |
| 40 | typedef std::unique_ptr<int> T; |
Marshall Clow | dfdac03 | 2013-11-15 22:42:10 +0000 | [diff] [blame] | 41 | optional<T> opt; |
| 42 | assert(std::hash<optional<T>>{}(opt) == 0); |
Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 43 | opt = std::unique_ptr<int>(new int(3)); |
Marshall Clow | dfdac03 | 2013-11-15 22:42:10 +0000 | [diff] [blame] | 44 | assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt)); |
Howard Hinnant | e7d746d | 2013-09-02 20:30:37 +0000 | [diff] [blame] | 45 | } |
| 46 | #endif // _LIBCPP_STD_VER > 11 |
| 47 | } |