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
12 // template <class U> constexpr T optional<T>::value_or(U&& v) const&;
15 #include <type_traits>
18 #include "test_macros.h"
26 constexpr Y(int i
) : i_(i
) {}
33 constexpr X(int i
) : i_(i
) {}
34 constexpr X(const Y
& y
) : i_(y
.i_
) {}
35 constexpr X(Y
&& y
) : i_(y
.i_
+1) {}
36 friend constexpr bool operator==(const X
& x
, const X
& y
)
37 {return x
.i_
== y
.i_
;}
43 constexpr optional
<X
> opt(2);
45 static_assert(opt
.value_or(y
) == 2, "");
48 constexpr optional
<X
> opt(2);
49 static_assert(opt
.value_or(Y(3)) == 2, "");
52 constexpr optional
<X
> opt
;
54 static_assert(opt
.value_or(y
) == 3, "");
57 constexpr optional
<X
> opt
;
58 static_assert(opt
.value_or(Y(3)) == 4, "");
61 const optional
<X
> opt(2);
63 assert(opt
.value_or(y
) == 2);
66 const optional
<X
> opt(2);
67 assert(opt
.value_or(Y(3)) == 2);
70 const optional
<X
> opt
;
72 assert(opt
.value_or(y
) == 3);
75 const optional
<X
> opt
;
76 assert(opt
.value_or(Y(3)) == 4);