Home | History | Annotate | Download | only in optional.specalg
      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, c++14
     11 // <optional>
     12 
     13 // template <class T, class... Args>
     14 //   constexpr optional<T> make_optional(Args&&... args);
     15 
     16 #include <optional>
     17 #include <string>
     18 #include <memory>
     19 #include <cassert>
     20 
     21 int main()
     22 {
     23     using std::optional;
     24     using std::make_optional;
     25 
     26     {
     27         constexpr auto opt = make_optional<int>('a');
     28         static_assert(*opt == int('a'), "");
     29     }
     30     {
     31         std::string s("123");
     32         auto opt = make_optional<std::string>(s);
     33         assert(*opt == s);
     34     }
     35     {
     36         std::unique_ptr<int> s(new int(3));
     37         auto opt = make_optional<std::unique_ptr<int>>(std::move(s));
     38         assert(**opt == 3);
     39         assert(s == nullptr);
     40     }
     41     {
     42         auto opt = make_optional<std::string>(4, 'X');
     43         assert(*opt == "XXXX");
     44     }
     45 }
     46