libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

deduct.pass.cpp (1426B)


      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 // UNSUPPORTED: c++98, c++03, c++11, c++14
     12 // UNSUPPORTED: clang-5, apple-clang-9
     13 // UNSUPPORTED: libcpp-no-deduction-guides
     14 // Clang 5 will generate bad implicit deduction guides
     15 //  Specifically, for the copy constructor.
     16 
     17 
     18 // template<class T>
     19 //   optional(T) -> optional<T>;
     20 
     21 
     22 #include <optional>
     23 #include <cassert>
     24 
     25 struct A {};
     26 
     27 int main()
     28 {
     29 //  Test the explicit deduction guides
     30     {
     31 //  optional(T)
     32     std::optional opt(5);
     33     static_assert(std::is_same_v<decltype(opt), std::optional<int>>, "");
     34     assert(static_cast<bool>(opt));
     35     assert(*opt == 5);
     36     }
     37 
     38     {
     39 //  optional(T)
     40     std::optional opt(A{});
     41     static_assert(std::is_same_v<decltype(opt), std::optional<A>>, "");
     42     assert(static_cast<bool>(opt));
     43     }
     44 
     45 //  Test the implicit deduction guides
     46     {
     47 //  optional(optional);
     48     std::optional<char> source('A');
     49     std::optional opt(source);
     50     static_assert(std::is_same_v<decltype(opt), std::optional<char>>, "");
     51     assert(static_cast<bool>(opt) == static_cast<bool>(source));
     52     assert(*opt == *source);
     53     }
     54 }