Home | History | Annotate | Download | only in optional.bad_optional_access
      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 // class bad_optional_access;
     13 // bad_optional_access& operator=(const bad_optional_access&);
     14 
     15 #include <experimental/optional>
     16 #include <string>
     17 #include <cstring>
     18 #include <type_traits>
     19 #include <cassert>
     20 
     21 int main()
     22 {
     23 #if _LIBCPP_STD_VER > 11
     24     using std::experimental::bad_optional_access;
     25 
     26     static_assert(std::is_nothrow_copy_assignable<bad_optional_access>::value, "");
     27     const std::string s1("one message");
     28     const std::string s2("another message");
     29     bad_optional_access e1(s1);
     30     bad_optional_access e2(s2);
     31     assert(std::strcmp(e1.what(), e2.what()) != 0);
     32     e1 = e2;
     33     assert(std::strcmp(e1.what(), e2.what()) == 0);
     34 #endif  // _LIBCPP_STD_VER > 11
     35 }
     36