Move <optional> into include/experimental, and into the std::experimental namespace, since it's not part of C++14, but of an upcoming TS
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@194867 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -11,13 +11,15 @@
|
||||
|
||||
// template <class U> optional<T>& operator=(U&& v);
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
};
|
||||
@@ -27,41 +29,41 @@ struct X
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
static_assert(std::is_assignable<std::optional<int>, int>::value, "");
|
||||
static_assert(std::is_assignable<std::optional<int>, int&>::value, "");
|
||||
static_assert(std::is_assignable<std::optional<int>&, int>::value, "");
|
||||
static_assert(std::is_assignable<std::optional<int>&, int&>::value, "");
|
||||
static_assert(std::is_assignable<std::optional<int>&, const int&>::value, "");
|
||||
static_assert(!std::is_assignable<const std::optional<int>&, const int&>::value, "");
|
||||
static_assert(!std::is_assignable<std::optional<int>, X>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>, int>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>, int&>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>&, int>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>&, int&>::value, "");
|
||||
static_assert(std::is_assignable<optional<int>&, const int&>::value, "");
|
||||
static_assert(!std::is_assignable<const optional<int>&, const int&>::value, "");
|
||||
static_assert(!std::is_assignable<optional<int>, X>::value, "");
|
||||
{
|
||||
std::optional<int> opt;
|
||||
optional<int> opt;
|
||||
opt = 1;
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 1);
|
||||
}
|
||||
{
|
||||
std::optional<int> opt;
|
||||
optional<int> opt;
|
||||
const int i = 2;
|
||||
opt = i;
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == i);
|
||||
}
|
||||
{
|
||||
std::optional<int> opt(3);
|
||||
optional<int> opt(3);
|
||||
const int i = 2;
|
||||
opt = i;
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == i);
|
||||
}
|
||||
{
|
||||
std::optional<std::unique_ptr<int>> opt;
|
||||
optional<std::unique_ptr<int>> opt;
|
||||
opt = std::unique_ptr<int>(new int(3));
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(**opt == 3);
|
||||
}
|
||||
{
|
||||
std::optional<std::unique_ptr<int>> opt(std::unique_ptr<int>(new int(2)));
|
||||
optional<std::unique_ptr<int>> opt(std::unique_ptr<int>(new int(2)));
|
||||
opt = std::unique_ptr<int>(new int(3));
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(**opt == 3);
|
||||
|
||||
@@ -11,12 +11,14 @@
|
||||
|
||||
// optional<T>& operator=(const optional<T>& rhs);
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
static bool throw_now;
|
||||
@@ -37,15 +39,15 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
std::optional<int> opt;
|
||||
constexpr std::optional<int> opt2;
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2;
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
std::optional<int> opt;
|
||||
constexpr std::optional<int> opt2(2);
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
@@ -53,15 +55,15 @@ int main()
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
std::optional<int> opt(3);
|
||||
constexpr std::optional<int> opt2;
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2;
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
std::optional<int> opt(3);
|
||||
constexpr std::optional<int> opt2(2);
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = opt2;
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
@@ -69,8 +71,8 @@ int main()
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
std::optional<X> opt;
|
||||
std::optional<X> opt2(X{});
|
||||
optional<X> opt;
|
||||
optional<X> opt2(X{});
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
try
|
||||
{
|
||||
|
||||
@@ -11,13 +11,15 @@
|
||||
|
||||
// template <class... Args> void optional<T>::emplace(Args&&... args);
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
@@ -58,61 +60,61 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
std::optional<int> opt;
|
||||
optional<int> opt;
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
std::optional<int> opt;
|
||||
optional<int> opt;
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 1);
|
||||
}
|
||||
{
|
||||
std::optional<int> opt(2);
|
||||
optional<int> opt(2);
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
std::optional<int> opt(2);
|
||||
optional<int> opt(2);
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == 1);
|
||||
}
|
||||
{
|
||||
std::optional<X> opt;
|
||||
optional<X> opt;
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X());
|
||||
}
|
||||
{
|
||||
std::optional<X> opt;
|
||||
optional<X> opt;
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1));
|
||||
}
|
||||
{
|
||||
std::optional<X> opt;
|
||||
optional<X> opt;
|
||||
opt.emplace(1, 2);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1, 2));
|
||||
}
|
||||
{
|
||||
std::optional<X> opt(X{3});
|
||||
optional<X> opt(X{3});
|
||||
opt.emplace();
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X());
|
||||
}
|
||||
{
|
||||
std::optional<X> opt(X{3});
|
||||
optional<X> opt(X{3});
|
||||
opt.emplace(1);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1));
|
||||
}
|
||||
{
|
||||
std::optional<X> opt(X{3});
|
||||
optional<X> opt(X{3});
|
||||
opt.emplace(1, 2);
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == X(1, 2));
|
||||
@@ -120,7 +122,7 @@ int main()
|
||||
{
|
||||
Y y;
|
||||
{
|
||||
std::optional<Y> opt(y);
|
||||
optional<Y> opt(y);
|
||||
assert(Y::dtor_called == false);
|
||||
opt.emplace();
|
||||
assert(Y::dtor_called == true);
|
||||
@@ -128,7 +130,7 @@ int main()
|
||||
}
|
||||
{
|
||||
Z z;
|
||||
std::optional<Z> opt(z);
|
||||
optional<Z> opt(z);
|
||||
try
|
||||
{
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
|
||||
@@ -12,13 +12,15 @@
|
||||
// template <class U, class... Args>
|
||||
// void optional<T>::emplace(initializer_list<U> il, Args&&... args);
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
class X
|
||||
{
|
||||
int i_;
|
||||
@@ -75,7 +77,7 @@ int main()
|
||||
{
|
||||
X x;
|
||||
{
|
||||
std::optional<X> opt(x);
|
||||
optional<X> opt(x);
|
||||
assert(X::dtor_called == false);
|
||||
opt.emplace({1, 2});
|
||||
assert(X::dtor_called == true);
|
||||
@@ -83,20 +85,20 @@ int main()
|
||||
}
|
||||
}
|
||||
{
|
||||
std::optional<std::vector<int>> opt;
|
||||
optional<std::vector<int>> opt;
|
||||
opt.emplace({1, 2, 3}, std::allocator<int>());
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == std::vector<int>({1, 2, 3}));
|
||||
}
|
||||
{
|
||||
std::optional<Y> opt;
|
||||
optional<Y> opt;
|
||||
opt.emplace({1, 2});
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
assert(*opt == Y({1, 2}));
|
||||
}
|
||||
{
|
||||
Z z;
|
||||
std::optional<Z> opt(z);
|
||||
optional<Z> opt(z);
|
||||
try
|
||||
{
|
||||
assert(static_cast<bool>(opt) == true);
|
||||
|
||||
@@ -13,12 +13,14 @@
|
||||
// noexcept(is_nothrow_move_assignable<T>::value &&
|
||||
// is_nothrow_move_constructible<T>::value);
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
static bool throw_now;
|
||||
@@ -45,16 +47,16 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
static_assert(std::is_nothrow_move_assignable<std::optional<int>>::value, "");
|
||||
std::optional<int> opt;
|
||||
constexpr std::optional<int> opt2;
|
||||
static_assert(std::is_nothrow_move_assignable<optional<int>>::value, "");
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2;
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
std::optional<int> opt;
|
||||
constexpr std::optional<int> opt2(2);
|
||||
optional<int> opt;
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
@@ -62,15 +64,15 @@ int main()
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
std::optional<int> opt(3);
|
||||
constexpr std::optional<int> opt2;
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2;
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == false, "");
|
||||
assert(static_cast<bool>(opt) == static_cast<bool>(opt2));
|
||||
}
|
||||
{
|
||||
std::optional<int> opt(3);
|
||||
constexpr std::optional<int> opt2(2);
|
||||
optional<int> opt(3);
|
||||
constexpr optional<int> opt2(2);
|
||||
opt = std::move(opt2);
|
||||
static_assert(static_cast<bool>(opt2) == true, "");
|
||||
static_assert(*opt2 == 2, "");
|
||||
@@ -78,9 +80,9 @@ int main()
|
||||
assert(*opt == *opt2);
|
||||
}
|
||||
{
|
||||
static_assert(!std::is_nothrow_move_assignable<std::optional<X>>::value, "");
|
||||
std::optional<X> opt;
|
||||
std::optional<X> opt2(X{});
|
||||
static_assert(!std::is_nothrow_move_assignable<optional<X>>::value, "");
|
||||
optional<X> opt;
|
||||
optional<X> opt2(X{});
|
||||
assert(static_cast<bool>(opt2) == true);
|
||||
try
|
||||
{
|
||||
@@ -95,7 +97,7 @@ int main()
|
||||
}
|
||||
}
|
||||
{
|
||||
static_assert(std::is_nothrow_move_assignable<std::optional<Y>>::value, "");
|
||||
static_assert(std::is_nothrow_move_assignable<optional<Y>>::value, "");
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
||||
|
||||
@@ -11,12 +11,16 @@
|
||||
|
||||
// optional<T>& operator=(nullopt_t) noexcept;
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt_t;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
struct X
|
||||
{
|
||||
static bool dtor_called;
|
||||
@@ -31,30 +35,30 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
std::optional<int> opt;
|
||||
static_assert(noexcept(opt = std::nullopt) == true, "");
|
||||
opt = std::nullopt;
|
||||
optional<int> opt;
|
||||
static_assert(noexcept(opt = nullopt) == true, "");
|
||||
opt = nullopt;
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
{
|
||||
std::optional<int> opt(3);
|
||||
opt = std::nullopt;
|
||||
optional<int> opt(3);
|
||||
opt = nullopt;
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
{
|
||||
std::optional<X> opt;
|
||||
static_assert(noexcept(opt = std::nullopt) == true, "");
|
||||
optional<X> opt;
|
||||
static_assert(noexcept(opt = nullopt) == true, "");
|
||||
assert(X::dtor_called == false);
|
||||
opt = std::nullopt;
|
||||
opt = nullopt;
|
||||
assert(X::dtor_called == false);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
{
|
||||
X x;
|
||||
{
|
||||
std::optional<X> opt(x);
|
||||
optional<X> opt(x);
|
||||
assert(X::dtor_called == false);
|
||||
opt = std::nullopt;
|
||||
opt = nullopt;
|
||||
assert(X::dtor_called == true);
|
||||
assert(static_cast<bool>(opt) == false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user