Add some constexpr tests for optional's move/copy ctor
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@303824 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -32,6 +32,16 @@ void test(InitArgs&&... args)
|
|||||||
assert(*lhs == *rhs);
|
assert(*lhs == *rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class ...InitArgs>
|
||||||
|
constexpr bool constexpr_test(InitArgs&&... args)
|
||||||
|
{
|
||||||
|
static_assert( std::is_trivially_copy_constructible_v<T>, ""); // requirement
|
||||||
|
const optional<T> rhs(std::forward<InitArgs>(args)...);
|
||||||
|
optional<T> lhs = rhs;
|
||||||
|
return (lhs.has_value() == rhs.has_value()) &&
|
||||||
|
(lhs.has_value() ? *lhs == *rhs : true);
|
||||||
|
}
|
||||||
|
|
||||||
void test_throwing_ctor() {
|
void test_throwing_ctor() {
|
||||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||||
struct Z {
|
struct Z {
|
||||||
@@ -108,6 +118,9 @@ int main()
|
|||||||
{
|
{
|
||||||
test<int>();
|
test<int>();
|
||||||
test<int>(3);
|
test<int>(3);
|
||||||
|
static_assert(constexpr_test<int>(), "" );
|
||||||
|
static_assert(constexpr_test<int>(3), "" );
|
||||||
|
|
||||||
{
|
{
|
||||||
const optional<const int> o(42);
|
const optional<const int> o(42);
|
||||||
optional<const int> o2(o);
|
optional<const int> o2(o);
|
||||||
|
|||||||
@@ -41,6 +41,17 @@ void test(InitArgs&&... args)
|
|||||||
assert(*lhs == *orig);
|
assert(*lhs == *orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class ...InitArgs>
|
||||||
|
constexpr bool constexpr_test(InitArgs&&... args)
|
||||||
|
{
|
||||||
|
static_assert( std::is_trivially_copy_constructible_v<T>, ""); // requirement
|
||||||
|
const optional<T> orig(std::forward<InitArgs>(args)...);
|
||||||
|
optional<T> rhs(orig);
|
||||||
|
optional<T> lhs = std::move(rhs);
|
||||||
|
return (lhs.has_value() == orig.has_value()) &&
|
||||||
|
(lhs.has_value() ? *lhs == *orig : true);
|
||||||
|
}
|
||||||
|
|
||||||
void test_throwing_ctor() {
|
void test_throwing_ctor() {
|
||||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||||
struct Z {
|
struct Z {
|
||||||
@@ -144,6 +155,9 @@ int main()
|
|||||||
{
|
{
|
||||||
test<int>();
|
test<int>();
|
||||||
test<int>(3);
|
test<int>(3);
|
||||||
|
static_assert(constexpr_test<int>(), "" );
|
||||||
|
static_assert(constexpr_test<int>(3), "" );
|
||||||
|
|
||||||
{
|
{
|
||||||
optional<const int> o(42);
|
optional<const int> o(42);
|
||||||
optional<const int> o2(std::move(o));
|
optional<const int> o2(std::move(o));
|
||||||
|
|||||||
Reference in New Issue
Block a user