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:
@@ -0,0 +1,267 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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, c++17, c++20
|
||||
|
||||
// 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>
|
||||
|
||||
// template<class F> constexpr auto and_then(F&&) &;
|
||||
// template<class F> constexpr auto and_then(F&&) &&;
|
||||
// template<class F> constexpr auto and_then(F&&) const&;
|
||||
// template<class F> constexpr auto and_then(F&&) const&&;
|
||||
|
||||
#include <cassert>
|
||||
#include <optional>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
struct LVal {
|
||||
constexpr std::optional<int> operator()(int&) { return 1; }
|
||||
std::optional<int> operator()(const int&) = delete;
|
||||
std::optional<int> operator()(int&&) = delete;
|
||||
std::optional<int> operator()(const int&&) = delete;
|
||||
};
|
||||
|
||||
struct CLVal {
|
||||
std::optional<int> operator()(int&) = delete;
|
||||
constexpr std::optional<int> operator()(const int&) { return 1; }
|
||||
std::optional<int> operator()(int&&) = delete;
|
||||
std::optional<int> operator()(const int&&) = delete;
|
||||
};
|
||||
|
||||
struct RVal {
|
||||
std::optional<int> operator()(int&) = delete;
|
||||
std::optional<int> operator()(const int&) = delete;
|
||||
constexpr std::optional<int> operator()(int&&) { return 1; }
|
||||
std::optional<int> operator()(const int&&) = delete;
|
||||
};
|
||||
|
||||
struct CRVal {
|
||||
std::optional<int> operator()(int&) = delete;
|
||||
std::optional<int> operator()(const int&) = delete;
|
||||
std::optional<int> operator()(int&&) = delete;
|
||||
constexpr std::optional<int> operator()(const int&&) { return 1; }
|
||||
};
|
||||
|
||||
struct RefQual {
|
||||
constexpr std::optional<int> operator()(int) & { return 1; }
|
||||
std::optional<int> operator()(int) const& = delete;
|
||||
std::optional<int> operator()(int) && = delete;
|
||||
std::optional<int> operator()(int) const&& = delete;
|
||||
};
|
||||
|
||||
struct CRefQual {
|
||||
std::optional<int> operator()(int) & = delete;
|
||||
constexpr std::optional<int> operator()(int) const& { return 1; }
|
||||
std::optional<int> operator()(int) && = delete;
|
||||
std::optional<int> operator()(int) const&& = delete;
|
||||
};
|
||||
|
||||
struct RVRefQual {
|
||||
std::optional<int> operator()(int) & = delete;
|
||||
std::optional<int> operator()(int) const& = delete;
|
||||
constexpr std::optional<int> operator()(int) && { return 1; }
|
||||
std::optional<int> operator()(int) const&& = delete;
|
||||
};
|
||||
|
||||
struct RVCRefQual {
|
||||
std::optional<int> operator()(int) & = delete;
|
||||
std::optional<int> operator()(int) const& = delete;
|
||||
std::optional<int> operator()(int) && = delete;
|
||||
constexpr std::optional<int> operator()(int) const&& { return 1; }
|
||||
};
|
||||
|
||||
struct NOLVal {
|
||||
constexpr std::optional<int> operator()(int&) { return std::nullopt; }
|
||||
std::optional<int> operator()(const int&) = delete;
|
||||
std::optional<int> operator()(int&&) = delete;
|
||||
std::optional<int> operator()(const int&&) = delete;
|
||||
};
|
||||
|
||||
struct NOCLVal {
|
||||
std::optional<int> operator()(int&) = delete;
|
||||
constexpr std::optional<int> operator()(const int&) { return std::nullopt; }
|
||||
std::optional<int> operator()(int&&) = delete;
|
||||
std::optional<int> operator()(const int&&) = delete;
|
||||
};
|
||||
|
||||
struct NORVal {
|
||||
std::optional<int> operator()(int&) = delete;
|
||||
std::optional<int> operator()(const int&) = delete;
|
||||
constexpr std::optional<int> operator()(int&&) { return std::nullopt; }
|
||||
std::optional<int> operator()(const int&&) = delete;
|
||||
};
|
||||
|
||||
struct NOCRVal {
|
||||
std::optional<int> operator()(int&) = delete;
|
||||
std::optional<int> operator()(const int&) = delete;
|
||||
std::optional<int> operator()(int&&) = delete;
|
||||
constexpr std::optional<int> operator()(const int&&) { return std::nullopt; }
|
||||
};
|
||||
|
||||
struct NORefQual {
|
||||
constexpr std::optional<int> operator()(int) & { return std::nullopt; }
|
||||
std::optional<int> operator()(int) const& = delete;
|
||||
std::optional<int> operator()(int) && = delete;
|
||||
std::optional<int> operator()(int) const&& = delete;
|
||||
};
|
||||
|
||||
struct NOCRefQual {
|
||||
std::optional<int> operator()(int) & = delete;
|
||||
constexpr std::optional<int> operator()(int) const& { return std::nullopt; }
|
||||
std::optional<int> operator()(int) && = delete;
|
||||
std::optional<int> operator()(int) const&& = delete;
|
||||
};
|
||||
|
||||
struct NORVRefQual {
|
||||
std::optional<int> operator()(int) & = delete;
|
||||
std::optional<int> operator()(int) const& = delete;
|
||||
constexpr std::optional<int> operator()(int) && { return std::nullopt; }
|
||||
std::optional<int> operator()(int) const&& = delete;
|
||||
};
|
||||
|
||||
struct NORVCRefQual {
|
||||
std::optional<int> operator()(int) & = delete;
|
||||
std::optional<int> operator()(int) const& = delete;
|
||||
std::optional<int> operator()(int) && = delete;
|
||||
constexpr std::optional<int> operator()(int) const&& { return std::nullopt; }
|
||||
};
|
||||
|
||||
struct NoCopy {
|
||||
NoCopy() = default;
|
||||
NoCopy(const NoCopy&) { assert(false); }
|
||||
std::optional<int> operator()(const NoCopy&&) { return 1; }
|
||||
};
|
||||
|
||||
struct NonConst {
|
||||
std::optional<int> non_const() { return 1; }
|
||||
};
|
||||
|
||||
constexpr void test_val_types() {
|
||||
// Test & overload
|
||||
{
|
||||
// Without & qualifier on F's operator()
|
||||
{
|
||||
std::optional<int> i{0};
|
||||
assert(i.and_then(LVal{}) == 1);
|
||||
assert(i.and_then(NOLVal{}) == std::nullopt);
|
||||
ASSERT_SAME_TYPE(decltype(i.and_then(LVal{})), std::optional<int>);
|
||||
}
|
||||
|
||||
//With & qualifier on F's operator()
|
||||
{
|
||||
std::optional<int> i{0};
|
||||
RefQual l{};
|
||||
assert(i.and_then(l) == 1);
|
||||
NORefQual nl{};
|
||||
assert(i.and_then(nl) == std::nullopt);
|
||||
ASSERT_SAME_TYPE(decltype(i.and_then(l)), std::optional<int>);
|
||||
}
|
||||
}
|
||||
|
||||
// Test const& overload
|
||||
{
|
||||
// Without & qualifier on F's operator()
|
||||
{
|
||||
const std::optional<int> i{0};
|
||||
assert(i.and_then(CLVal{}) == 1);
|
||||
assert(i.and_then(NOCLVal{}) == std::nullopt);
|
||||
ASSERT_SAME_TYPE(decltype(i.and_then(CLVal{})), std::optional<int>);
|
||||
}
|
||||
|
||||
//With & qualifier on F's operator()
|
||||
{
|
||||
const std::optional<int> i{0};
|
||||
const CRefQual l{};
|
||||
assert(i.and_then(l) == 1);
|
||||
const NOCRefQual nl{};
|
||||
assert(i.and_then(nl) == std::nullopt);
|
||||
ASSERT_SAME_TYPE(decltype(i.and_then(l)), std::optional<int>);
|
||||
}
|
||||
}
|
||||
|
||||
// Test && overload
|
||||
{
|
||||
// Without & qualifier on F's operator()
|
||||
{
|
||||
std::optional<int> i{0};
|
||||
assert(std::move(i).and_then(RVal{}) == 1);
|
||||
assert(std::move(i).and_then(NORVal{}) == std::nullopt);
|
||||
ASSERT_SAME_TYPE(decltype(std::move(i).and_then(RVal{})), std::optional<int>);
|
||||
}
|
||||
|
||||
//With & qualifier on F's operator()
|
||||
{
|
||||
std::optional<int> i{0};
|
||||
assert(i.and_then(RVRefQual{}) == 1);
|
||||
assert(i.and_then(NORVRefQual{}) == std::nullopt);
|
||||
ASSERT_SAME_TYPE(decltype(i.and_then(RVRefQual{})), std::optional<int>);
|
||||
}
|
||||
}
|
||||
|
||||
// Test const&& overload
|
||||
{
|
||||
// Without & qualifier on F's operator()
|
||||
{
|
||||
const std::optional<int> i{0};
|
||||
assert(std::move(i).and_then(CRVal{}) == 1);
|
||||
assert(std::move(i).and_then(NOCRVal{}) == std::nullopt);
|
||||
ASSERT_SAME_TYPE(decltype(std::move(i).and_then(CRVal{})), std::optional<int>);
|
||||
}
|
||||
|
||||
//With & qualifier on F's operator()
|
||||
{
|
||||
const std::optional<int> i{0};
|
||||
const RVCRefQual l{};
|
||||
assert(i.and_then(std::move(l)) == 1);
|
||||
const NORVCRefQual nl{};
|
||||
assert(i.and_then(std::move(nl)) == std::nullopt);
|
||||
ASSERT_SAME_TYPE(decltype(i.and_then(std::move(l))), std::optional<int>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check that the lambda body is not instantiated during overload resolution
|
||||
constexpr void test_sfinae() {
|
||||
std::optional<NonConst> opt{};
|
||||
auto l = [](auto&& x) { return x.non_const(); };
|
||||
opt.and_then(l);
|
||||
std::move(opt).and_then(l);
|
||||
}
|
||||
|
||||
constexpr bool test() {
|
||||
test_val_types();
|
||||
std::optional<int> opt{};
|
||||
const auto& copt = opt;
|
||||
|
||||
const auto never_called = [](int) {
|
||||
assert(false);
|
||||
return std::optional<int>{};
|
||||
};
|
||||
|
||||
opt.and_then(never_called);
|
||||
std::move(opt).and_then(never_called);
|
||||
copt.and_then(never_called);
|
||||
std::move(copt).and_then(never_called);
|
||||
|
||||
std::optional<NoCopy> nc;
|
||||
const auto& cnc = nc;
|
||||
std::move(cnc).and_then(NoCopy{});
|
||||
std::move(nc).and_then(NoCopy{});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
static_assert(test());
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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, c++17, c++20
|
||||
// <optional>
|
||||
|
||||
// template<class F> constexpr optional or_else(F&&) &&;
|
||||
// template<class F> constexpr optional or_else(F&&) const&;
|
||||
|
||||
#include "MoveOnly.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <optional>
|
||||
|
||||
struct NonMovable {
|
||||
NonMovable() = default;
|
||||
NonMovable(NonMovable&&) = delete;
|
||||
};
|
||||
|
||||
template <class Opt, class F>
|
||||
concept has_or_else = requires(Opt&& opt, F&& f) {
|
||||
{std::forward<Opt>(opt).or_else(std::forward<F>(f))};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
std::optional<T> return_optional() {}
|
||||
|
||||
static_assert(has_or_else<std::optional<int>&, decltype(return_optional<int>)>);
|
||||
static_assert(has_or_else<std::optional<int>&&, decltype(return_optional<int>)>);
|
||||
static_assert(!has_or_else<std::optional<MoveOnly>&, decltype(return_optional<MoveOnly>)>);
|
||||
static_assert(has_or_else<std::optional<MoveOnly>&&, decltype(return_optional<MoveOnly>)>);
|
||||
static_assert(!has_or_else<std::optional<NonMovable>&, decltype(return_optional<NonMovable>)>);
|
||||
static_assert(!has_or_else<std::optional<NonMovable>&&, decltype(return_optional<NonMovable>)>);
|
||||
|
||||
std::optional<int> take_int(int) { return 0; }
|
||||
void take_int_return_void(int) {}
|
||||
|
||||
static_assert(!has_or_else<std::optional<int>, decltype(take_int)>);
|
||||
static_assert(!has_or_else<std::optional<int>, decltype(take_int_return_void)>);
|
||||
static_assert(!has_or_else<std::optional<int>, int>);
|
||||
|
||||
constexpr bool test() {
|
||||
{
|
||||
std::optional<int> opt;
|
||||
assert(opt.or_else([] { return std::optional<int>{0}; }) == 0);
|
||||
opt = 1;
|
||||
opt.or_else([] {
|
||||
assert(false);
|
||||
return std::optional<int>{};
|
||||
});
|
||||
}
|
||||
{
|
||||
std::optional<MoveOnly> opt;
|
||||
opt = std::move(opt).or_else([] { return std::optional<MoveOnly>{MoveOnly{}}; });
|
||||
std::move(opt).or_else([] {
|
||||
assert(false);
|
||||
return std::optional<MoveOnly>{};
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
static_assert(test());
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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, c++17, c++20
|
||||
|
||||
// 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>
|
||||
|
||||
// template<class F> constexpr auto transform(F&&) &;
|
||||
// template<class F> constexpr auto transform(F&&) &&;
|
||||
// template<class F> constexpr auto transform(F&&) const&;
|
||||
// template<class F> constexpr auto transform(F&&) const&&;
|
||||
|
||||
#include "test_macros.h"
|
||||
#include <cassert>
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
|
||||
struct LVal {
|
||||
constexpr int operator()(int&) { return 1; }
|
||||
int operator()(const int&) = delete;
|
||||
int operator()(int&&) = delete;
|
||||
int operator()(const int&&) = delete;
|
||||
};
|
||||
|
||||
struct CLVal {
|
||||
int operator()(int&) = delete;
|
||||
constexpr int operator()(const int&) { return 1; }
|
||||
int operator()(int&&) = delete;
|
||||
int operator()(const int&&) = delete;
|
||||
};
|
||||
|
||||
struct RVal {
|
||||
int operator()(int&) = delete;
|
||||
int operator()(const int&) = delete;
|
||||
constexpr int operator()(int&&) { return 1; }
|
||||
int operator()(const int&&) = delete;
|
||||
};
|
||||
|
||||
struct CRVal {
|
||||
int operator()(int&) = delete;
|
||||
int operator()(const int&) = delete;
|
||||
int operator()(int&&) = delete;
|
||||
constexpr int operator()(const int&&) { return 1; }
|
||||
};
|
||||
|
||||
struct RefQual {
|
||||
constexpr int operator()(int) & { return 1; }
|
||||
int operator()(int) const& = delete;
|
||||
int operator()(int) && = delete;
|
||||
int operator()(int) const&& = delete;
|
||||
};
|
||||
|
||||
struct CRefQual {
|
||||
int operator()(int) & = delete;
|
||||
constexpr int operator()(int) const& { return 1; }
|
||||
int operator()(int) && = delete;
|
||||
int operator()(int) const&& = delete;
|
||||
};
|
||||
|
||||
struct RVRefQual {
|
||||
int operator()(int) & = delete;
|
||||
int operator()(int) const& = delete;
|
||||
constexpr int operator()(int) && { return 1; }
|
||||
int operator()(int) const&& = delete;
|
||||
};
|
||||
|
||||
struct RVCRefQual {
|
||||
int operator()(int) & = delete;
|
||||
int operator()(int) const& = delete;
|
||||
int operator()(int) && = delete;
|
||||
constexpr int operator()(int) const&& { return 1; }
|
||||
};
|
||||
|
||||
struct NoCopy {
|
||||
NoCopy() = default;
|
||||
NoCopy(const NoCopy&) { assert(false); }
|
||||
int operator()(const NoCopy&&) { return 1; }
|
||||
};
|
||||
|
||||
struct NoMove {
|
||||
NoMove() = default;
|
||||
NoMove(NoMove&&) = delete;
|
||||
NoMove operator()(const NoCopy&&) { return NoMove{}; }
|
||||
};
|
||||
|
||||
constexpr void test_val_types() {
|
||||
// Test & overload
|
||||
{
|
||||
// Without & qualifier on F's operator()
|
||||
{
|
||||
std::optional<int> i{0};
|
||||
assert(i.transform(LVal{}) == 1);
|
||||
ASSERT_SAME_TYPE(decltype(i.transform(LVal{})), std::optional<int>);
|
||||
}
|
||||
|
||||
//With & qualifier on F's operator()
|
||||
{
|
||||
std::optional<int> i{0};
|
||||
RefQual l{};
|
||||
assert(i.transform(l) == 1);
|
||||
ASSERT_SAME_TYPE(decltype(i.transform(l)), std::optional<int>);
|
||||
}
|
||||
}
|
||||
|
||||
// Test const& overload
|
||||
{
|
||||
// Without & qualifier on F's operator()
|
||||
{
|
||||
const std::optional<int> i{0};
|
||||
assert(i.transform(CLVal{}) == 1);
|
||||
ASSERT_SAME_TYPE(decltype(i.transform(CLVal{})), std::optional<int>);
|
||||
}
|
||||
|
||||
//With & qualifier on F's operator()
|
||||
{
|
||||
const std::optional<int> i{0};
|
||||
const CRefQual l{};
|
||||
assert(i.transform(l) == 1);
|
||||
ASSERT_SAME_TYPE(decltype(i.transform(l)), std::optional<int>);
|
||||
}
|
||||
}
|
||||
|
||||
// Test && overload
|
||||
{
|
||||
// Without & qualifier on F's operator()
|
||||
{
|
||||
std::optional<int> i{0};
|
||||
assert(std::move(i).transform(RVal{}) == 1);
|
||||
ASSERT_SAME_TYPE(decltype(std::move(i).transform(RVal{})), std::optional<int>);
|
||||
}
|
||||
|
||||
//With & qualifier on F's operator()
|
||||
{
|
||||
std::optional<int> i{0};
|
||||
assert(i.transform(RVRefQual{}) == 1);
|
||||
ASSERT_SAME_TYPE(decltype(i.transform(RVRefQual{})), std::optional<int>);
|
||||
}
|
||||
}
|
||||
|
||||
// Test const&& overload
|
||||
{
|
||||
// Without & qualifier on F's operator()
|
||||
{
|
||||
const std::optional<int> i{0};
|
||||
assert(std::move(i).transform(CRVal{}) == 1);
|
||||
ASSERT_SAME_TYPE(decltype(std::move(i).transform(CRVal{})), std::optional<int>);
|
||||
}
|
||||
|
||||
//With & qualifier on F's operator()
|
||||
{
|
||||
const std::optional<int> i{0};
|
||||
const RVCRefQual l{};
|
||||
assert(i.transform(std::move(l)) == 1);
|
||||
ASSERT_SAME_TYPE(decltype(i.transform(std::move(l))), std::optional<int>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct NonConst {
|
||||
int non_const() { return 1; }
|
||||
};
|
||||
|
||||
// check that the lambda body is not instantiated during overload resolution
|
||||
constexpr void test_sfinae() {
|
||||
std::optional<NonConst> opt{};
|
||||
auto l = [](auto&& x) { return x.non_const(); };
|
||||
opt.transform(l);
|
||||
std::move(opt).transform(l);
|
||||
}
|
||||
|
||||
constexpr bool test() {
|
||||
test_sfinae();
|
||||
test_val_types();
|
||||
std::optional<int> opt;
|
||||
const auto& copt = opt;
|
||||
|
||||
const auto never_called = [](int) {
|
||||
assert(false);
|
||||
return 0;
|
||||
};
|
||||
|
||||
opt.transform(never_called);
|
||||
std::move(opt).transform(never_called);
|
||||
copt.transform(never_called);
|
||||
std::move(copt).transform(never_called);
|
||||
|
||||
std::optional<NoCopy> nc;
|
||||
const auto& cnc = nc;
|
||||
std::move(nc).transform(NoCopy{});
|
||||
std::move(cnc).transform(NoCopy{});
|
||||
|
||||
std::move(nc).transform(NoMove{});
|
||||
std::move(cnc).transform(NoMove{});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
test();
|
||||
static_assert(test());
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user