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,19 +11,21 @@
|
||||
|
||||
// constexpr explicit optional<T>::operator bool() const noexcept;
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
|
||||
{
|
||||
constexpr std::optional<int> opt;
|
||||
constexpr optional<int> opt;
|
||||
static_assert(!opt, "");
|
||||
}
|
||||
{
|
||||
constexpr std::optional<int> opt(0);
|
||||
constexpr optional<int> opt(0);
|
||||
static_assert(opt, "");
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
@@ -15,12 +15,14 @@
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
|
||||
#endif
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const {return 3;}
|
||||
@@ -33,12 +35,12 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
std::optional<X> opt(X{});
|
||||
optional<X> opt(X{});
|
||||
assert((*opt).test() == 4);
|
||||
}
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
{
|
||||
std::optional<X> opt;
|
||||
optional<X> opt;
|
||||
assert((*opt).test() == 3);
|
||||
assert(false);
|
||||
}
|
||||
|
||||
@@ -15,12 +15,14 @@
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
|
||||
#endif
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const {return 3;}
|
||||
@@ -37,16 +39,16 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr std::optional<X> opt(X{});
|
||||
constexpr optional<X> opt(X{});
|
||||
static_assert((*opt).test() == 3, "");
|
||||
}
|
||||
{
|
||||
constexpr std::optional<Y> opt(Y{});
|
||||
constexpr optional<Y> opt(Y{});
|
||||
assert((*opt).test() == 2);
|
||||
}
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
{
|
||||
const std::optional<X> opt;
|
||||
const optional<X> opt;
|
||||
assert((*opt).test() == 3);
|
||||
assert(false);
|
||||
}
|
||||
|
||||
@@ -15,12 +15,14 @@
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
|
||||
#endif
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int test() const {return 2;}
|
||||
@@ -33,12 +35,12 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
std::optional<X> opt(X{});
|
||||
optional<X> opt(X{});
|
||||
assert(opt->test() == 3);
|
||||
}
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
{
|
||||
std::optional<X> opt;
|
||||
optional<X> opt;
|
||||
assert(opt->test() == 3);
|
||||
assert(false);
|
||||
}
|
||||
|
||||
@@ -15,12 +15,14 @@
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
|
||||
#endif
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const {return 3;}
|
||||
@@ -43,20 +45,20 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr std::optional<X> opt(X{});
|
||||
constexpr optional<X> opt(X{});
|
||||
static_assert(opt->test() == 3, "");
|
||||
}
|
||||
{
|
||||
constexpr std::optional<Y> opt(Y{});
|
||||
constexpr optional<Y> opt(Y{});
|
||||
assert(opt->test() == 2);
|
||||
}
|
||||
{
|
||||
constexpr std::optional<Z> opt(Z{});
|
||||
constexpr optional<Z> opt(Z{});
|
||||
assert(opt->test() == 1);
|
||||
}
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
{
|
||||
const std::optional<X> opt;
|
||||
const optional<X> opt;
|
||||
assert(opt->test() == 3);
|
||||
assert(false);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,15 @@
|
||||
|
||||
// T& optional<T>::value();
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::bad_optional_access;
|
||||
|
||||
struct X
|
||||
{
|
||||
X() = default;
|
||||
@@ -31,18 +34,18 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
std::optional<X> opt;
|
||||
optional<X> opt;
|
||||
opt.emplace();
|
||||
assert(opt.value().test() == 4);
|
||||
}
|
||||
{
|
||||
std::optional<X> opt;
|
||||
optional<X> opt;
|
||||
try
|
||||
{
|
||||
opt.value();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::bad_optional_access&)
|
||||
catch (const bad_optional_access&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,14 @@
|
||||
|
||||
// constexpr const T& optional<T>::value() const;
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const {return 3;}
|
||||
@@ -29,7 +31,7 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr std::optional<X> opt;
|
||||
constexpr optional<X> opt;
|
||||
static_assert(opt.value().test() == 3, "");
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -11,12 +11,17 @@
|
||||
|
||||
// constexpr const T& optional<T>::value() const;
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::in_place_t;
|
||||
using std::experimental::in_place;
|
||||
using std::experimental::bad_optional_access;
|
||||
|
||||
struct X
|
||||
{
|
||||
X() = default;
|
||||
@@ -31,21 +36,21 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr std::optional<X> opt(std::in_place);
|
||||
constexpr optional<X> opt(in_place);
|
||||
static_assert(opt.value().test() == 3, "");
|
||||
}
|
||||
{
|
||||
const std::optional<X> opt(std::in_place);
|
||||
const optional<X> opt(in_place);
|
||||
assert(opt.value().test() == 3);
|
||||
}
|
||||
{
|
||||
const std::optional<X> opt;
|
||||
const optional<X> opt;
|
||||
try
|
||||
{
|
||||
opt.value();
|
||||
assert(false);
|
||||
}
|
||||
catch (const std::bad_optional_access&)
|
||||
catch (const bad_optional_access&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,16 @@
|
||||
|
||||
// template <class U> T optional<T>::value_or(U&& v) &&;
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
using std::experimental::in_place_t;
|
||||
using std::experimental::in_place;
|
||||
|
||||
struct Y
|
||||
{
|
||||
int i_;
|
||||
@@ -42,24 +46,24 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
std::optional<X> opt(std::in_place, 2);
|
||||
optional<X> opt(in_place, 2);
|
||||
Y y(3);
|
||||
assert(std::move(opt).value_or(y) == 2);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
std::optional<X> opt(std::in_place, 2);
|
||||
optional<X> opt(in_place, 2);
|
||||
assert(std::move(opt).value_or(Y(3)) == 2);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
std::optional<X> opt;
|
||||
optional<X> opt;
|
||||
Y y(3);
|
||||
assert(std::move(opt).value_or(y) == 3);
|
||||
assert(!opt);
|
||||
}
|
||||
{
|
||||
std::optional<X> opt;
|
||||
optional<X> opt;
|
||||
assert(std::move(opt).value_or(Y(3)) == 4);
|
||||
assert(!opt);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,14 @@
|
||||
|
||||
// template <class U> constexpr T optional<T>::value_or(U&& v) const&;
|
||||
|
||||
#include <optional>
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct Y
|
||||
{
|
||||
int i_;
|
||||
@@ -41,39 +43,39 @@ int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr std::optional<X> opt(2);
|
||||
constexpr optional<X> opt(2);
|
||||
constexpr Y y(3);
|
||||
static_assert(opt.value_or(y) == 2, "");
|
||||
}
|
||||
{
|
||||
constexpr std::optional<X> opt(2);
|
||||
constexpr optional<X> opt(2);
|
||||
static_assert(opt.value_or(Y(3)) == 2, "");
|
||||
}
|
||||
{
|
||||
constexpr std::optional<X> opt;
|
||||
constexpr optional<X> opt;
|
||||
constexpr Y y(3);
|
||||
static_assert(opt.value_or(y) == 3, "");
|
||||
}
|
||||
{
|
||||
constexpr std::optional<X> opt;
|
||||
constexpr optional<X> opt;
|
||||
static_assert(opt.value_or(Y(3)) == 4, "");
|
||||
}
|
||||
{
|
||||
const std::optional<X> opt(2);
|
||||
const optional<X> opt(2);
|
||||
const Y y(3);
|
||||
assert(opt.value_or(y) == 2);
|
||||
}
|
||||
{
|
||||
const std::optional<X> opt(2);
|
||||
const optional<X> opt(2);
|
||||
assert(opt.value_or(Y(3)) == 2);
|
||||
}
|
||||
{
|
||||
const std::optional<X> opt;
|
||||
const optional<X> opt;
|
||||
const Y y(3);
|
||||
assert(opt.value_or(y) == 3);
|
||||
}
|
||||
{
|
||||
const std::optional<X> opt;
|
||||
const optional<X> opt;
|
||||
assert(opt.value_or(Y(3)) == 4);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
Reference in New Issue
Block a user