Home | History | Annotate | Download | only in optional.hash
      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 // UNSUPPORTED: c++98, c++03, c++11
     11 // <optional>
     12 
     13 // template <class T> struct hash<optional<T>>;
     14 
     15 #include <experimental/optional>
     16 #include <string>
     17 #include <memory>
     18 #include <cassert>
     19 
     20 
     21 int main()
     22 {
     23     using std::experimental::optional;
     24 
     25     {
     26         typedef int T;
     27         optional<T> opt;
     28         assert(std::hash<optional<T>>{}(opt) == 0);
     29         opt = 2;
     30         assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
     31     }
     32     {
     33         typedef std::string T;
     34         optional<T> opt;
     35         assert(std::hash<optional<T>>{}(opt) == 0);
     36         opt = std::string("123");
     37         assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
     38     }
     39     {
     40         typedef std::unique_ptr<int> T;
     41         optional<T> opt;
     42         assert(std::hash<optional<T>>{}(opt) == 0);
     43         opt = std::unique_ptr<int>(new int(3));
     44         assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt));
     45     }
     46 }
     47