You've already forked Zygisk-Assistant
mirror of
https://github.com/snake-4/Zygisk-Assistant.git
synced 2025-09-06 06:37:02 +00:00
Initial commit
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// constexpr explicit optional<T>::operator bool() const noexcept;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
using std::optional;
|
||||
{
|
||||
const optional<int> opt; ((void)opt);
|
||||
ASSERT_NOEXCEPT(bool(opt));
|
||||
static_assert(!std::is_convertible<optional<int>, bool>::value, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<int> opt;
|
||||
static_assert(!opt, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<int> opt(0);
|
||||
static_assert(opt, "");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// constexpr T& optional<T>::operator*() &;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const& {return 3;}
|
||||
int test() & {return 4;}
|
||||
constexpr int test() const&& {return 5;}
|
||||
int test() && {return 6;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
constexpr int test() {return 7;}
|
||||
};
|
||||
|
||||
constexpr int
|
||||
test()
|
||||
{
|
||||
optional<Y> opt{Y{}};
|
||||
return (*opt).test();
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
optional<X> opt; ((void)opt);
|
||||
ASSERT_SAME_TYPE(decltype(*opt), X&);
|
||||
LIBCPP_STATIC_ASSERT(noexcept(*opt));
|
||||
// ASSERT_NOT_NOEXCEPT(*opt);
|
||||
// FIXME: This assertion fails with GCC because it can see that
|
||||
// (A) operator*() is constexpr, and
|
||||
// (B) there is no path through the function that throws.
|
||||
// It's arguable if this is the correct behavior for the noexcept
|
||||
// operator.
|
||||
// Regardless this function should still be noexcept(false) because
|
||||
// it has a narrow contract.
|
||||
}
|
||||
{
|
||||
optional<X> opt(X{});
|
||||
assert((*opt).test() == 4);
|
||||
}
|
||||
static_assert(test() == 7, "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// constexpr const T& optional<T>::operator*() const &;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const& {return 3;}
|
||||
int test() & {return 4;}
|
||||
constexpr int test() const&& {return 5;}
|
||||
int test() && {return 6;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int test() const {return 2;}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
const optional<X> opt; ((void)opt);
|
||||
ASSERT_SAME_TYPE(decltype(*opt), X const&);
|
||||
LIBCPP_STATIC_ASSERT(noexcept(*opt));
|
||||
// ASSERT_NOT_NOEXCEPT(*opt);
|
||||
// FIXME: This assertion fails with GCC because it can see that
|
||||
// (A) operator*() is constexpr, and
|
||||
// (B) there is no path through the function that throws.
|
||||
// It's arguable if this is the correct behavior for the noexcept
|
||||
// operator.
|
||||
// Regardless this function should still be noexcept(false) because
|
||||
// it has a narrow contract.
|
||||
}
|
||||
{
|
||||
constexpr optional<X> opt(X{});
|
||||
static_assert((*opt).test() == 3, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<Y> opt(Y{});
|
||||
assert((*opt).test() == 2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// constexpr T&& optional<T>::operator*() const &&;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const& {return 3;}
|
||||
int test() & {return 4;}
|
||||
constexpr int test() const&& {return 5;}
|
||||
int test() && {return 6;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int test() const && {return 2;}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
const optional<X> opt; ((void)opt);
|
||||
ASSERT_SAME_TYPE(decltype(*std::move(opt)), X const &&);
|
||||
LIBCPP_STATIC_ASSERT(noexcept(*opt));
|
||||
// ASSERT_NOT_NOEXCEPT(*std::move(opt));
|
||||
// FIXME: This assertion fails with GCC because it can see that
|
||||
// (A) operator*() is constexpr, and
|
||||
// (B) there is no path through the function that throws.
|
||||
// It's arguable if this is the correct behavior for the noexcept
|
||||
// operator.
|
||||
// Regardless this function should still be noexcept(false) because
|
||||
// it has a narrow contract.
|
||||
}
|
||||
{
|
||||
constexpr optional<X> opt(X{});
|
||||
static_assert((*std::move(opt)).test() == 5, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<Y> opt(Y{});
|
||||
assert((*std::move(opt)).test() == 2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// constexpr T&& optional<T>::operator*() &&;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const& {return 3;}
|
||||
int test() & {return 4;}
|
||||
constexpr int test() const&& {return 5;}
|
||||
int test() && {return 6;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
constexpr int test() && {return 7;}
|
||||
};
|
||||
|
||||
constexpr int
|
||||
test()
|
||||
{
|
||||
optional<Y> opt{Y{}};
|
||||
return (*std::move(opt)).test();
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
optional<X> opt; ((void)opt);
|
||||
ASSERT_SAME_TYPE(decltype(*std::move(opt)), X&&);
|
||||
LIBCPP_STATIC_ASSERT(noexcept(*opt));
|
||||
// ASSERT_NOT_NOEXCEPT(*std::move(opt));
|
||||
// FIXME: This assertion fails with GCC because it can see that
|
||||
// (A) operator*() is constexpr, and
|
||||
// (B) there is no path through the function that throws.
|
||||
// It's arguable if this is the correct behavior for the noexcept
|
||||
// operator.
|
||||
// Regardless this function should still be noexcept(false) because
|
||||
// it has a narrow contract.
|
||||
}
|
||||
{
|
||||
optional<X> opt(X{});
|
||||
assert((*std::move(opt)).test() == 6);
|
||||
}
|
||||
static_assert(test() == 7, "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// constexpr bool optional<T>::has_value() const noexcept;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
using std::optional;
|
||||
{
|
||||
const optional<int> opt; ((void)opt);
|
||||
ASSERT_NOEXCEPT(opt.has_value());
|
||||
ASSERT_SAME_TYPE(decltype(opt.has_value()), bool);
|
||||
}
|
||||
{
|
||||
constexpr optional<int> opt;
|
||||
static_assert(!opt.has_value(), "");
|
||||
}
|
||||
{
|
||||
constexpr optional<int> opt(0);
|
||||
static_assert(opt.has_value(), "");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// constexpr T* optional<T>::operator->();
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
int test() noexcept {return 3;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
constexpr int test() {return 3;}
|
||||
};
|
||||
|
||||
constexpr int
|
||||
test()
|
||||
{
|
||||
optional<Y> opt{Y{}};
|
||||
return opt->test();
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
std::optional<X> opt; ((void)opt);
|
||||
ASSERT_SAME_TYPE(decltype(opt.operator->()), X*);
|
||||
// ASSERT_NOT_NOEXCEPT(opt.operator->());
|
||||
// FIXME: This assertion fails with GCC because it can see that
|
||||
// (A) operator->() is constexpr, and
|
||||
// (B) there is no path through the function that throws.
|
||||
// It's arguable if this is the correct behavior for the noexcept
|
||||
// operator.
|
||||
// Regardless this function should still be noexcept(false) because
|
||||
// it has a narrow contract.
|
||||
}
|
||||
{
|
||||
optional<X> opt(X{});
|
||||
assert(opt->test() == 3);
|
||||
}
|
||||
{
|
||||
static_assert(test() == 3, "");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// constexpr const T* optional<T>::operator->() const;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const {return 3;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
int test() const noexcept {return 2;}
|
||||
};
|
||||
|
||||
struct Z
|
||||
{
|
||||
const Z* operator&() const;
|
||||
constexpr int test() const {return 1;}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
const std::optional<X> opt; ((void)opt);
|
||||
ASSERT_SAME_TYPE(decltype(opt.operator->()), X const*);
|
||||
// ASSERT_NOT_NOEXCEPT(opt.operator->());
|
||||
// FIXME: This assertion fails with GCC because it can see that
|
||||
// (A) operator->() is constexpr, and
|
||||
// (B) there is no path through the function that throws.
|
||||
// It's arguable if this is the correct behavior for the noexcept
|
||||
// operator.
|
||||
// Regardless this function should still be noexcept(false) because
|
||||
// it has a narrow contract.
|
||||
}
|
||||
{
|
||||
constexpr optional<X> opt(X{});
|
||||
static_assert(opt->test() == 3, "");
|
||||
}
|
||||
{
|
||||
constexpr optional<Y> opt(Y{});
|
||||
assert(opt->test() == 2);
|
||||
}
|
||||
{
|
||||
constexpr optional<Z> opt(Z{});
|
||||
static_assert(opt->test() == 1, "");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
|
||||
// Throwing bad_optional_access is supported starting in macosx10.13
|
||||
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}} && !no-exceptions
|
||||
|
||||
// <optional>
|
||||
|
||||
// constexpr T& optional<T>::value() &;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
using std::bad_optional_access;
|
||||
|
||||
struct X
|
||||
{
|
||||
X() = default;
|
||||
X(const X&) = delete;
|
||||
constexpr int test() const & {return 3;}
|
||||
int test() & {return 4;}
|
||||
constexpr int test() const && {return 5;}
|
||||
int test() && {return 6;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
constexpr int test() & {return 7;}
|
||||
};
|
||||
|
||||
constexpr int
|
||||
test()
|
||||
{
|
||||
optional<Y> opt{Y{}};
|
||||
return opt.value().test();
|
||||
}
|
||||
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
optional<X> opt; ((void)opt);
|
||||
ASSERT_NOT_NOEXCEPT(opt.value());
|
||||
ASSERT_SAME_TYPE(decltype(opt.value()), X&);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
opt.emplace();
|
||||
assert(opt.value().test() == 4);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
{
|
||||
optional<X> opt;
|
||||
try
|
||||
{
|
||||
(void)opt.value();
|
||||
assert(false);
|
||||
}
|
||||
catch (const bad_optional_access&)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
static_assert(test() == 7, "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// constexpr const T& optional<T>::value() const &;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
using std::optional;
|
||||
|
||||
struct X
|
||||
{
|
||||
constexpr int test() const {return 3;}
|
||||
int test() {return 4;}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
constexpr optional<X> opt;
|
||||
static_assert(opt.value().test() == 3, "");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
|
||||
// Throwing bad_optional_access is supported starting in macosx10.13
|
||||
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}} && !no-exceptions
|
||||
|
||||
// <optional>
|
||||
|
||||
// constexpr const T& optional<T>::value() const &;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
using std::in_place_t;
|
||||
using std::in_place;
|
||||
using std::bad_optional_access;
|
||||
|
||||
struct X
|
||||
{
|
||||
X() = default;
|
||||
X(const X&) = delete;
|
||||
constexpr int test() const & {return 3;}
|
||||
int test() & {return 4;}
|
||||
constexpr int test() const && {return 5;}
|
||||
int test() && {return 6;}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
const optional<X> opt; ((void)opt);
|
||||
ASSERT_NOT_NOEXCEPT(opt.value());
|
||||
ASSERT_SAME_TYPE(decltype(opt.value()), X const&);
|
||||
}
|
||||
{
|
||||
constexpr optional<X> opt(in_place);
|
||||
static_assert(opt.value().test() == 3, "");
|
||||
}
|
||||
{
|
||||
const optional<X> opt(in_place);
|
||||
assert(opt.value().test() == 3);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
{
|
||||
const optional<X> opt;
|
||||
try
|
||||
{
|
||||
(void)opt.value();
|
||||
assert(false);
|
||||
}
|
||||
catch (const bad_optional_access&)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
|
||||
// Throwing bad_optional_access is supported starting in macosx10.13
|
||||
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}} && !no-exceptions
|
||||
|
||||
// <optional>
|
||||
|
||||
// constexpr const T& optional<T>::value() const &&;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
using std::in_place_t;
|
||||
using std::in_place;
|
||||
using std::bad_optional_access;
|
||||
|
||||
struct X
|
||||
{
|
||||
X() = default;
|
||||
X(const X&) = delete;
|
||||
constexpr int test() const & {return 3;}
|
||||
int test() & {return 4;}
|
||||
constexpr int test() const && {return 5;}
|
||||
int test() && {return 6;}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
const optional<X> opt; ((void)opt);
|
||||
ASSERT_NOT_NOEXCEPT(std::move(opt).value());
|
||||
ASSERT_SAME_TYPE(decltype(std::move(opt).value()), X const&&);
|
||||
}
|
||||
{
|
||||
constexpr optional<X> opt(in_place);
|
||||
static_assert(std::move(opt).value().test() == 5, "");
|
||||
}
|
||||
{
|
||||
const optional<X> opt(in_place);
|
||||
assert(std::move(opt).value().test() == 5);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
{
|
||||
const optional<X> opt;
|
||||
try
|
||||
{
|
||||
(void)std::move(opt).value();
|
||||
assert(false);
|
||||
}
|
||||
catch (const bad_optional_access&)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// template <class U> constexpr T optional<T>::value_or(U&& v) &&;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
using std::in_place_t;
|
||||
using std::in_place;
|
||||
|
||||
struct Y
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr Y(int i) : i_(i) {}
|
||||
};
|
||||
|
||||
struct X
|
||||
{
|
||||
int i_;
|
||||
|
||||
constexpr X(int i) : i_(i) {}
|
||||
constexpr X(X&& x) : i_(x.i_) {x.i_ = 0;}
|
||||
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_;}
|
||||
};
|
||||
|
||||
constexpr int test()
|
||||
{
|
||||
{
|
||||
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);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
static_assert(test() == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// template <class U> constexpr T optional<T>::value_or(U&& v) const&;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::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_;}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// UNSUPPORTED: c++03, c++11, c++14
|
||||
// <optional>
|
||||
|
||||
// Throwing bad_optional_access is supported starting in macosx10.13
|
||||
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12}} && !no-exceptions
|
||||
|
||||
// constexpr T& optional<T>::value() &&;
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using std::optional;
|
||||
using std::bad_optional_access;
|
||||
|
||||
struct X
|
||||
{
|
||||
X() = default;
|
||||
X(const X&) = delete;
|
||||
constexpr int test() const & {return 3;}
|
||||
int test() & {return 4;}
|
||||
constexpr int test() const && {return 5;}
|
||||
int test() && {return 6;}
|
||||
};
|
||||
|
||||
struct Y
|
||||
{
|
||||
constexpr int test() && {return 7;}
|
||||
};
|
||||
|
||||
constexpr int
|
||||
test()
|
||||
{
|
||||
optional<Y> opt{Y{}};
|
||||
return std::move(opt).value().test();
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
optional<X> opt; ((void)opt);
|
||||
ASSERT_NOT_NOEXCEPT(std::move(opt).value());
|
||||
ASSERT_SAME_TYPE(decltype(std::move(opt).value()), X&&);
|
||||
}
|
||||
{
|
||||
optional<X> opt;
|
||||
opt.emplace();
|
||||
assert(std::move(opt).value().test() == 6);
|
||||
}
|
||||
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||
{
|
||||
optional<X> opt;
|
||||
try
|
||||
{
|
||||
(void)std::move(opt).value();
|
||||
assert(false);
|
||||
}
|
||||
catch (const bad_optional_access&)
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
static_assert(test() == 7, "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user