1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
13 // template <class... Args>
14 // constexpr explicit optional(in_place_t, Args&&... args);
17 #include <type_traits>
20 #include "test_macros.h"
23 using std::in_place_t
;
33 X(int i
, int j
) : i_(i
), j_(j
) {}
37 friend bool operator==(const X
& x
, const X
& y
)
38 {return x
.i_
== y
.i_
&& x
.j_
== y
.j_
;}
46 constexpr Y() : i_(0) {}
47 constexpr Y(int i
) : i_(i
) {}
48 constexpr Y(int i
, int j
) : i_(i
), j_(j
) {}
50 friend constexpr bool operator==(const Y
& x
, const Y
& y
)
51 {return x
.i_
== y
.i_
&& x
.j_
== y
.j_
;}
57 Z(int) {TEST_THROW(6);}
64 constexpr optional
<int> opt(in_place
, 5);
65 static_assert(static_cast<bool>(opt
) == true, "");
66 static_assert(*opt
== 5, "");
68 struct test_constexpr_ctor
69 : public optional
<int>
71 constexpr test_constexpr_ctor(in_place_t
, int i
)
72 : optional
<int>(in_place
, i
) {}
77 optional
<const int> opt(in_place
, 5);
81 const optional
<X
> opt(in_place
);
82 assert(static_cast<bool>(opt
) == true);
86 const optional
<X
> opt(in_place
, 5);
87 assert(static_cast<bool>(opt
) == true);
91 const optional
<X
> opt(in_place
, 5, 4);
92 assert(static_cast<bool>(opt
) == true);
93 assert(*opt
== X(5, 4));
96 constexpr optional
<Y
> opt(in_place
);
97 static_assert(static_cast<bool>(opt
) == true, "");
98 static_assert(*opt
== Y(), "");
100 struct test_constexpr_ctor
103 constexpr test_constexpr_ctor(in_place_t
)
104 : optional
<Y
>(in_place
) {}
109 constexpr optional
<Y
> opt(in_place
, 5);
110 static_assert(static_cast<bool>(opt
) == true, "");
111 static_assert(*opt
== Y(5), "");
113 struct test_constexpr_ctor
116 constexpr test_constexpr_ctor(in_place_t
, int i
)
117 : optional
<Y
>(in_place
, i
) {}
122 constexpr optional
<Y
> opt(in_place
, 5, 4);
123 static_assert(static_cast<bool>(opt
) == true, "");
124 static_assert(*opt
== Y(5, 4), "");
126 struct test_constexpr_ctor
129 constexpr test_constexpr_ctor(in_place_t
, int i
, int j
)
130 : optional
<Y
>(in_place
, i
, j
) {}
134 #ifndef TEST_HAS_NO_EXCEPTIONS
138 const optional
<Z
> opt(in_place
, 1);