Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// constexpr explicit optional<T>::operator bool() const noexcept;
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
using std::experimental::optional;
|
||||
|
||||
{
|
||||
constexpr optional<int> opt;
|
||||
static_assert(!opt, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<int> opt(0);
|
||||
static_assert(opt, "");
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// T& optional<T>::operator*();
|
||||
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
|
||||
#endif
|
||||
|
||||
#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;}
|
||||
int test() {return 4;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<X> opt(X{});
|
||||
assert((*opt).test() == 4);
|
||||
}
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
{
|
||||
optional<X> opt;
|
||||
assert((*opt).test() == 3);
|
||||
assert(false);
|
||||
}
|
||||
#endif // _LIBCPP_DEBUG
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// constexpr const T& optional<T>::operator*() const;
|
||||
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
|
||||
#endif
|
||||
|
||||
#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;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int test() const {return 2;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr optional<X> opt(X{});
|
||||
static_assert((*opt).test() == 3, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<Y> opt(Y{});
|
||||
assert((*opt).test() == 2);
|
||||
}
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
{
|
||||
const optional<X> opt;
|
||||
assert((*opt).test() == 3);
|
||||
assert(false);
|
||||
}
|
||||
#endif // _LIBCPP_DEBUG
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// constexpr T* optional<T>::operator->();
|
||||
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
|
||||
#endif
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
constexpr int test() const {return 3;}
|
||||
#else
|
||||
constexpr int test() {return 3;}
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr optional<X> opt(X{});
|
||||
static_assert(opt->test() == 3, "");
|
||||
}
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
{
|
||||
optional<X> opt;
|
||||
assert(opt->test() == 3);
|
||||
assert(false);
|
||||
}
|
||||
#endif // _LIBCPP_DEBUG
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// constexpr const T* optional<T>::operator->() const;
|
||||
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
|
||||
#endif
|
||||
|
||||
#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;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int test() const {return 2;}
|
||||
};
|
||||
|
||||
struct Z
|
||||
{
|
||||
const Z* operator&() const {return this;}
|
||||
constexpr int test() const {return 1;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr optional<X> opt(X{});
|
||||
static_assert(opt->test() == 3, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<Y> opt(Y{});
|
||||
assert(opt->test() == 2);
|
||||
}
|
||||
{
|
||||
constexpr optional<Z> opt(Z{});
|
||||
assert(opt->test() == 1);
|
||||
}
|
||||
#ifdef _LIBCPP_DEBUG
|
||||
{
|
||||
const optional<X> opt;
|
||||
assert(opt->test() == 3);
|
||||
assert(false);
|
||||
}
|
||||
#endif // _LIBCPP_DEBUG
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// T& optional<T>::value();
|
||||
|
||||
#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;
|
||||
X(const X&) = delete;
|
||||
constexpr int test() const {return 3;}
|
||||
int test() {return 4;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<X> opt;
|
||||
opt.emplace();
|
||||
assert(opt.value().test() == 4);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
try
|
||||
{
|
||||
opt.value();
|
||||
assert(false);
|
||||
}
|
||||
catch (const bad_optional_access&)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// constexpr const T& optional<T>::value() const;
|
||||
|
||||
#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;}
|
||||
int test() {return 4;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr optional<X> opt;
|
||||
static_assert(opt.value().test() == 3, "");
|
||||
}
|
||||
#else
|
||||
#error
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// constexpr const T& optional<T>::value() const;
|
||||
|
||||
#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;
|
||||
X(const X&) = delete;
|
||||
constexpr int test() const {return 3;}
|
||||
int test() {return 4;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr optional<X> opt(in_place);
|
||||
static_assert(opt.value().test() == 3, "");
|
||||
}
|
||||
{
|
||||
const optional<X> opt(in_place);
|
||||
assert(opt.value().test() == 3);
|
||||
}
|
||||
{
|
||||
const optional<X> opt;
|
||||
try
|
||||
{
|
||||
opt.value();
|
||||
assert(false);
|
||||
}
|
||||
catch (const bad_optional_access&)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// template <class U> T optional<T>::value_or(U&& v) &&;
|
||||
|
||||
#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_;
|
||||
|
||||
Y(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
X(int i) : i_(i) {}
|
||||
X(X&& x) : i_(x.i_) {x.i_ = 0;}
|
||||
X(const Y& y) : i_(y.i_) {}
|
||||
X(Y&& y) : i_(y.i_+1) {}
|
||||
friend constexpr bool operator==(const X& x, const X& y)
|
||||
{return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
optional<X> opt(in_place, 2);
|
||||
Y y(3);
|
||||
assert(std::move(opt).value_or(y) == 2);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
optional<X> opt(in_place, 2);
|
||||
assert(std::move(opt).value_or(Y(3)) == 2);
|
||||
assert(*opt == 0);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
Y y(3);
|
||||
assert(std::move(opt).value_or(y) == 3);
|
||||
assert(!opt);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
assert(std::move(opt).value_or(Y(3)) == 4);
|
||||
assert(!opt);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <optional>
|
||||
|
||||
// template <class U> constexpr T optional<T>::value_or(U&& v) const&;
|
||||
|
||||
#include <experimental/optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
using std::experimental::optional;
|
||||
|
||||
struct Y
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr Y(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
constexpr X(const Y& y) : i_(y.i_) {}
|
||||
constexpr X(Y&& y) : i_(y.i_+1) {}
|
||||
friend constexpr bool operator==(const X& x, const X& y)
|
||||
{return x.i_ == y.i_;}
|
||||
};
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
int main()
|
||||
{
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
{
|
||||
constexpr optional<X> opt(2);
|
||||
constexpr Y y(3);
|
||||
static_assert(opt.value_or(y) == 2, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<X> opt(2);
|
||||
static_assert(opt.value_or(Y(3)) == 2, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<X> opt;
|
||||
constexpr Y y(3);
|
||||
static_assert(opt.value_or(y) == 3, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<X> opt;
|
||||
static_assert(opt.value_or(Y(3)) == 4, "");
|
||||
}
|
||||
{
|
||||
const optional<X> opt(2);
|
||||
const Y y(3);
|
||||
assert(opt.value_or(y) == 2);
|
||||
}
|
||||
{
|
||||
const optional<X> opt(2);
|
||||
assert(opt.value_or(Y(3)) == 2);
|
||||
}
|
||||
{
|
||||
const optional<X> opt;
|
||||
const Y y(3);
|
||||
assert(opt.value_or(y) == 3);
|
||||
}
|
||||
{
|
||||
const optional<X> opt;
|
||||
assert(opt.value_or(Y(3)) == 4);
|
||||
}
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
}
|
Reference in New Issue
Block a user