mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 12:02:36 +08:00
add missing constexpr to optional::value_or
[Credit to cpplearner] Differential Revision: https://reviews.llvm.org/D27850 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@304813 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -897,7 +897,7 @@ public:
|
|||||||
|
|
||||||
template <class _Up>
|
template <class _Up>
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
value_type value_or(_Up&& __v) &&
|
constexpr value_type value_or(_Up&& __v) &&
|
||||||
{
|
{
|
||||||
static_assert(is_move_constructible_v<value_type>,
|
static_assert(is_move_constructible_v<value_type>,
|
||||||
"optional<T>::value_or: T must be move constructible");
|
"optional<T>::value_or: T must be move constructible");
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
||||||
// <optional>
|
// <optional>
|
||||||
|
|
||||||
// template <class U> T optional<T>::value_or(U&& v) &&;
|
// template <class U> constexpr T optional<T>::value_or(U&& v) &&;
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -26,22 +26,22 @@ struct Y
|
|||||||
{
|
{
|
||||||
int i_;
|
int i_;
|
||||||
|
|
||||||
Y(int i) : i_(i) {}
|
constexpr Y(int i) : i_(i) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct X
|
struct X
|
||||||
{
|
{
|
||||||
int i_;
|
int i_;
|
||||||
|
|
||||||
X(int i) : i_(i) {}
|
constexpr X(int i) : i_(i) {}
|
||||||
X(X&& x) : i_(x.i_) {x.i_ = 0;}
|
constexpr X(X&& x) : i_(x.i_) {x.i_ = 0;}
|
||||||
X(const Y& y) : i_(y.i_) {}
|
constexpr X(const Y& y) : i_(y.i_) {}
|
||||||
X(Y&& y) : i_(y.i_+1) {}
|
constexpr X(Y&& y) : i_(y.i_+1) {}
|
||||||
friend constexpr bool operator==(const X& x, const X& y)
|
friend constexpr bool operator==(const X& x, const X& y)
|
||||||
{return x.i_ == y.i_;}
|
{return x.i_ == y.i_;}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
constexpr int test()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
optional<X> opt(in_place, 2);
|
optional<X> opt(in_place, 2);
|
||||||
@@ -65,4 +65,10 @@ int main()
|
|||||||
assert(std::move(opt).value_or(Y(3)) == 4);
|
assert(std::move(opt).value_or(Y(3)) == 4);
|
||||||
assert(!opt);
|
assert(!opt);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
static_assert(test() == 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user