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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
// https://llvm.org/PR23141
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
struct Fun
|
||||
{
|
||||
template<typename T, typename U>
|
||||
void operator()(T &&, U &&) const
|
||||
{
|
||||
static_assert(std::is_same<U, int &>::value, "");
|
||||
}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
std::bind(Fun{}, std::placeholders::_1, 42)("hello");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
// Check that the call operators have the proper return type and that they
|
||||
// only SFINAE away when too few arguments are provided. Otherwise they should
|
||||
// be well formed and should ignore any additional arguments.
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int dummy = 42;
|
||||
|
||||
int return_value(int) { return dummy; }
|
||||
int& return_lvalue(int) { return dummy; }
|
||||
const int& return_const_lvalue(int) { return dummy; }
|
||||
int&& return_rvalue(int) { return std::move(dummy); }
|
||||
const int&& return_const_rvalue(int) { return std::move(dummy); }
|
||||
|
||||
template <class Bind, class ...Args>
|
||||
auto CheckCallImp(int)
|
||||
-> decltype((std::declval<Bind>()(std::declval<Args>()...)), std::true_type{});
|
||||
|
||||
template <class Bind, class ...>
|
||||
auto CheckCallImp(long) -> std::false_type;
|
||||
|
||||
template <class ...Args>
|
||||
constexpr bool CheckCall() {
|
||||
return decltype(CheckCallImp<Args...>(0))::value;
|
||||
}
|
||||
|
||||
template <class Expect, class Fn>
|
||||
void do_test(Fn* func) {
|
||||
using namespace std::placeholders;
|
||||
auto ret = std::bind(func, _1);
|
||||
auto ret_r = std::bind<Expect>(func, _1);
|
||||
using Bind = decltype(ret);
|
||||
using BindR = decltype(ret_r);
|
||||
|
||||
using Ret = decltype(ret(42));
|
||||
using Ret2 = decltype(ret(42, 43)); // Test that the extra argument is discarded.
|
||||
using RetR = decltype(ret_r(42));
|
||||
using RetR2 = decltype(ret_r(42, 43));
|
||||
|
||||
static_assert(std::is_same<Ret, Expect>::value, "");
|
||||
static_assert(std::is_same<Ret2, Expect>::value, "");
|
||||
static_assert(std::is_same<RetR, Expect>::value, "");
|
||||
static_assert(std::is_same<RetR2, Expect>::value, "");
|
||||
|
||||
Expect exp = ret(100); // the input value is ignored. dummy is returned.
|
||||
Expect exp2 = ret(101, 102);
|
||||
Expect exp_r = ret_r(100);
|
||||
Expect exp_r2 = ret_r(101, 102);
|
||||
|
||||
assert(exp == 42);
|
||||
assert(exp2 == 42);
|
||||
assert(exp_r == 42);
|
||||
assert(exp_r2 == 42);
|
||||
|
||||
if ((std::is_reference<Expect>::value)) {
|
||||
assert(&exp == &dummy);
|
||||
assert(&exp2 == &dummy);
|
||||
assert(&exp_r == &dummy);
|
||||
assert(&exp_r2 == &dummy);
|
||||
}
|
||||
// Check that the call operator SFINAE's away when too few arguments
|
||||
// are provided but is well-formed otherwise.
|
||||
{
|
||||
LIBCPP_STATIC_ASSERT(!CheckCall<Bind>(), "");
|
||||
static_assert(CheckCall<Bind, int>(), "");
|
||||
static_assert(CheckCall<Bind, int, int>(), "");
|
||||
LIBCPP_STATIC_ASSERT(!CheckCall<BindR>(), "");
|
||||
static_assert(CheckCall<BindR, int>(), "");
|
||||
static_assert(CheckCall<BindR, int, int>(), "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Test but with an explicit return type which differs from the real one.
|
||||
template <class Expect, class Fn>
|
||||
void do_test_r(Fn* func) {
|
||||
using namespace std::placeholders;
|
||||
auto ret = std::bind<Expect>(func, _1);
|
||||
using Bind = decltype(ret);
|
||||
using Ret = decltype(ret(42));
|
||||
using Ret2 = decltype(ret(42, 43)); // Test that the extra argument is discarded.
|
||||
static_assert(std::is_same<Ret, Expect>::value, "");
|
||||
static_assert(std::is_same<Ret2, Expect>::value, "");
|
||||
Expect exp = ret(100); // the input value is ignored
|
||||
Expect exp2 = ret(101, 102);
|
||||
assert(exp == 42);
|
||||
assert(exp2 == 42);
|
||||
// Check that the call operator SFINAE's away when too few arguments
|
||||
// are provided but is well-formed otherwise.
|
||||
{
|
||||
LIBCPP_STATIC_ASSERT(!CheckCall<Bind>(), "");
|
||||
static_assert(CheckCall<Bind, int>(), "");
|
||||
static_assert(CheckCall<Bind, int, int>(), "");
|
||||
}
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
do_test<int>(return_value);
|
||||
do_test<int&>(return_lvalue);
|
||||
do_test<const int&>(return_const_lvalue);
|
||||
do_test<int&&>(return_rvalue);
|
||||
do_test<const int&&>(return_const_rvalue);
|
||||
|
||||
do_test_r<long>(return_value);
|
||||
do_test_r<long>(return_lvalue);
|
||||
do_test_r<long>(return_const_lvalue);
|
||||
do_test_r<long>(return_rvalue);
|
||||
do_test_r<long>(return_const_rvalue);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Address Sanitizer doesn't instrument weak symbols on Linux. When a key
|
||||
// function is defined for bad_function_call's vtable, its typeinfo and vtable
|
||||
// will be defined as strong symbols in the library and weak symbols in other
|
||||
// translation units. Only the strong symbol will be instrumented, increasing
|
||||
// its size (due to the redzone) and leading to a serious ODR violation
|
||||
// resulting in a crash.
|
||||
// Some relevant bugs:
|
||||
// https://github.com/google/sanitizers/issues/1017
|
||||
// https://github.com/google/sanitizers/issues/619
|
||||
// https://github.com/google/sanitizers/issues/398
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68016
|
||||
// UNSUPPORTED: c++03, asan
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
// https://llvm.org/PR16385
|
||||
|
||||
#include <functional>
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
float _pow(float a, float b)
|
||||
{
|
||||
return std::pow(a, b);
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
std::function<float(float, float)> fnc = _pow;
|
||||
auto task = std::bind(fnc, 2.f, 4.f);
|
||||
auto task2(task);
|
||||
assert(task() == 16);
|
||||
assert(task2() == 16);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
// https://llvm.org/PR22003
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
struct DummyUnaryFunction
|
||||
{
|
||||
template <typename S>
|
||||
int operator()(S const &) const { return 0; }
|
||||
};
|
||||
|
||||
struct BadUnaryFunction
|
||||
{
|
||||
template <typename S>
|
||||
constexpr int operator()(S const &) const
|
||||
{
|
||||
// Trigger a compile error if this function is instantiated.
|
||||
// The constexpr is needed so that it is instantiated while checking
|
||||
// __invoke_of<BadUnaryFunction &, ...>.
|
||||
static_assert(!std::is_same<S, S>::value, "Shit");
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
// Check that BadUnaryFunction::operator()(S const &) is not
|
||||
// instantiated when checking if BadUnaryFunction is a nested bind
|
||||
// expression during b(0). See PR22003.
|
||||
auto b = std::bind(DummyUnaryFunction(), BadUnaryFunction());
|
||||
b(0);
|
||||
auto b2 = std::bind<long>(DummyUnaryFunction(), BadUnaryFunction());
|
||||
b2(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
template <class R, class F>
|
||||
void
|
||||
test(F f, R expected)
|
||||
{
|
||||
assert(f() == expected);
|
||||
}
|
||||
|
||||
template <class R, class F>
|
||||
void
|
||||
test_const(const F& f, R expected)
|
||||
{
|
||||
assert(f() == expected);
|
||||
}
|
||||
|
||||
int f() {return 1;}
|
||||
|
||||
struct A_int_0
|
||||
{
|
||||
int operator()() {return 4;}
|
||||
int operator()() const {return 5;}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test(std::bind(f), 1);
|
||||
test(std::bind(&f), 1);
|
||||
test(std::bind(A_int_0()), 4);
|
||||
test_const(std::bind(A_int_0()), 5);
|
||||
|
||||
test(std::bind<int>(f), 1);
|
||||
test(std::bind<int>(&f), 1);
|
||||
test(std::bind<int>(A_int_0()), 4);
|
||||
test_const(std::bind<int>(A_int_0()), 5);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+293
@@ -0,0 +1,293 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int count = 0;
|
||||
|
||||
// 1 arg, return void
|
||||
|
||||
void f_void_1(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
struct A_void_1
|
||||
{
|
||||
void operator()(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
void mem1() {++count;}
|
||||
void mem2() const {count += 2;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_1()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
int i = 2;
|
||||
std::bind(f_void_1, _1)(i);
|
||||
assert(count == save_count + 2);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
int i = 2;
|
||||
std::bind(f_void_1, i)();
|
||||
assert(count == save_count + 2);
|
||||
save_count = count;
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
void (*fp)(int) = f_void_1;
|
||||
int i = 3;
|
||||
std::bind(fp, _1)(i);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (*fp)(int) = f_void_1;
|
||||
int i = 3;
|
||||
std::bind(fp, i)();
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_void_1 a0;
|
||||
int i = 4;
|
||||
std::bind(a0, _1)(i);
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
A_void_1 a0;
|
||||
int i = 4;
|
||||
std::bind(a0, i)();
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() = &A_void_1::mem1;
|
||||
A_void_1 a;
|
||||
std::bind(fp, _1)(a);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
A_void_1* ap = &a;
|
||||
std::bind(fp, _1)(ap);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (A_void_1::*fp)() = &A_void_1::mem1;
|
||||
A_void_1 a;
|
||||
std::bind(fp, a)();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
A_void_1* ap = &a;
|
||||
std::bind(fp, ap)();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() const = &A_void_1::mem2;
|
||||
A_void_1 a;
|
||||
std::bind(fp, _1)(a);
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
A_void_1* ap = &a;
|
||||
std::bind(fp, _1)(ap);
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (A_void_1::*fp)() const = &A_void_1::mem2;
|
||||
A_void_1 a;
|
||||
std::bind(fp, a)();
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
A_void_1* ap = &a;
|
||||
std::bind(fp, ap)();
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
// 1 arg, return int
|
||||
|
||||
int f_int_1(int i)
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
struct A_int_1
|
||||
{
|
||||
A_int_1() : data_(5) {}
|
||||
int operator()(int i)
|
||||
{
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
int mem1() {return 3;}
|
||||
int mem2() const {return 4;}
|
||||
int data_;
|
||||
};
|
||||
|
||||
void
|
||||
test_int_1()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
// function
|
||||
{
|
||||
int i = 2;
|
||||
assert(std::bind(f_int_1, _1)(i) == 3);
|
||||
assert(std::bind(f_int_1, i)() == 3);
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
int (*fp)(int) = f_int_1;
|
||||
int i = 3;
|
||||
assert(std::bind(fp, _1)(i) == 4);
|
||||
assert(std::bind(fp, i)() == 4);
|
||||
}
|
||||
// functor
|
||||
{
|
||||
int i = 4;
|
||||
assert(std::bind(A_int_1(), _1)(i) == 3);
|
||||
assert(std::bind(A_int_1(), i)() == 3);
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::mem1, _1)(a) == 3);
|
||||
assert(std::bind(&A_int_1::mem1, a)() == 3);
|
||||
A_int_1* ap = &a;
|
||||
assert(std::bind(&A_int_1::mem1, _1)(ap) == 3);
|
||||
assert(std::bind(&A_int_1::mem1, ap)() == 3);
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4);
|
||||
assert(std::bind(&A_int_1::mem2, A_int_1())() == 4);
|
||||
A_int_1* ap = &a;
|
||||
assert(std::bind(&A_int_1::mem2, _1)(ap) == 4);
|
||||
assert(std::bind(&A_int_1::mem2, ap)() == 4);
|
||||
}
|
||||
// member data pointer
|
||||
{
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 5);
|
||||
assert(std::bind(&A_int_1::data_, a)() == 5);
|
||||
A_int_1* ap = &a;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 5);
|
||||
std::bind(&A_int_1::data_, _1)(a) = 6;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 6);
|
||||
assert(std::bind(&A_int_1::data_, _1)(ap) == 6);
|
||||
std::bind(&A_int_1::data_, _1)(ap) = 7;
|
||||
assert(std::bind(&A_int_1::data_, _1)(ap) == 7);
|
||||
}
|
||||
}
|
||||
|
||||
// 2 arg, return void
|
||||
|
||||
void f_void_2(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
struct A_void_2
|
||||
{
|
||||
void operator()(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
void mem1(int i) {count += i;}
|
||||
void mem2(int i) const {count += i;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_2()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
int i = 2;
|
||||
int j = 3;
|
||||
std::bind(f_void_2, _1, _2)(i, j);
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
std::bind(f_void_2, i, _1)(j);
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
std::bind(f_void_2, i, j)();
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
int j = 3;
|
||||
std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), j);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
std::bind(&A_void_2::mem1, _2, _1)(j, A_void_2());
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
struct TFENode
|
||||
{
|
||||
bool foo(unsigned long long) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
test3()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
const auto f = bind(&TFENode::foo, _1, 0UL);
|
||||
const TFENode n = TFENode{};
|
||||
bool b = f(n);
|
||||
assert(b);
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test_void_1();
|
||||
test_int_1();
|
||||
test_void_2();
|
||||
test3();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+271
@@ -0,0 +1,271 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int count = 0;
|
||||
|
||||
// 1 arg, return void
|
||||
|
||||
void f_void_1(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
struct A_void_1
|
||||
{
|
||||
void operator()(int i)
|
||||
{
|
||||
count += i;
|
||||
}
|
||||
|
||||
void mem1() {++count;}
|
||||
void mem2() const {count += 2;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_1()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
std::bind(f_void_1, _1)(2);
|
||||
assert(count == save_count + 2);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
std::bind(f_void_1, 2)();
|
||||
assert(count == save_count + 2);
|
||||
save_count = count;
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
void (*fp)(int) = f_void_1;
|
||||
std::bind(fp, _1)(3);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (*fp)(int) = f_void_1;
|
||||
std::bind(fp, 3)();
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
// functor
|
||||
{
|
||||
A_void_1 a0;
|
||||
std::bind(a0, _1)(4);
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
A_void_1 a0;
|
||||
std::bind(a0, 4)();
|
||||
assert(count == save_count+4);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() = &A_void_1::mem1;
|
||||
std::bind(fp, _1)(A_void_1());
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
A_void_1 a;
|
||||
std::bind(fp, _1)(&a);
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (A_void_1::*fp)() = &A_void_1::mem1;
|
||||
std::bind(fp, A_void_1())();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
A_void_1 a;
|
||||
std::bind(fp, &a)();
|
||||
assert(count == save_count+1);
|
||||
save_count = count;
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
void (A_void_1::*fp)() const = &A_void_1::mem2;
|
||||
std::bind(fp, _1)(A_void_1());
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
A_void_1 a;
|
||||
std::bind(fp, _1)(&a);
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
}
|
||||
{
|
||||
void (A_void_1::*fp)() const = &A_void_1::mem2;
|
||||
std::bind(fp, A_void_1())();
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
A_void_1 a;
|
||||
std::bind(fp, &a)();
|
||||
assert(count == save_count+2);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
// 1 arg, return int
|
||||
|
||||
int f_int_1(int i)
|
||||
{
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
struct A_int_1
|
||||
{
|
||||
A_int_1() : data_(5) {}
|
||||
int operator()(int i)
|
||||
{
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
int mem1() {return 3;}
|
||||
int mem2() const {return 4;}
|
||||
int data_;
|
||||
};
|
||||
|
||||
void
|
||||
test_int_1()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
// function
|
||||
{
|
||||
assert(std::bind(f_int_1, _1)(2) == 3);
|
||||
assert(std::bind(f_int_1, 2)() == 3);
|
||||
}
|
||||
// function pointer
|
||||
{
|
||||
int (*fp)(int) = f_int_1;
|
||||
assert(std::bind(fp, _1)(3) == 4);
|
||||
assert(std::bind(fp, 3)() == 4);
|
||||
}
|
||||
// functor
|
||||
{
|
||||
assert(std::bind(A_int_1(), _1)(4) == 3);
|
||||
assert(std::bind(A_int_1(), 4)() == 3);
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
assert(std::bind(&A_int_1::mem1, _1)(A_int_1()) == 3);
|
||||
assert(std::bind(&A_int_1::mem1, A_int_1())() == 3);
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::mem1, _1)(&a) == 3);
|
||||
assert(std::bind(&A_int_1::mem1, &a)() == 3);
|
||||
}
|
||||
// const member function pointer
|
||||
{
|
||||
assert(std::bind(&A_int_1::mem2, _1)(A_int_1()) == 4);
|
||||
assert(std::bind(&A_int_1::mem2, A_int_1())() == 4);
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::mem2, _1)(&a) == 4);
|
||||
assert(std::bind(&A_int_1::mem2, &a)() == 4);
|
||||
}
|
||||
// member data pointer
|
||||
{
|
||||
assert(std::bind(&A_int_1::data_, _1)(A_int_1()) == 5);
|
||||
assert(std::bind(&A_int_1::data_, A_int_1())() == 5);
|
||||
A_int_1 a;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 5);
|
||||
std::bind(&A_int_1::data_, _1)(a) = 6;
|
||||
assert(std::bind(&A_int_1::data_, _1)(a) == 6);
|
||||
assert(std::bind(&A_int_1::data_, _1)(&a) == 6);
|
||||
std::bind(&A_int_1::data_, _1)(&a) = 7;
|
||||
assert(std::bind(&A_int_1::data_, _1)(&a) == 7);
|
||||
}
|
||||
}
|
||||
|
||||
// 2 arg, return void
|
||||
|
||||
void f_void_2(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
struct A_void_2
|
||||
{
|
||||
void operator()(int i, int j)
|
||||
{
|
||||
count += i+j;
|
||||
}
|
||||
|
||||
void mem1(int i) {count += i;}
|
||||
void mem2(int i) const {count += i;}
|
||||
};
|
||||
|
||||
void
|
||||
test_void_2()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
int save_count = count;
|
||||
// function
|
||||
{
|
||||
std::bind(f_void_2, _1, _2)(2, 3);
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
std::bind(f_void_2, 2, _1)(3);
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
std::bind(f_void_2, 2, 3)();
|
||||
assert(count == save_count+5);
|
||||
save_count = count;
|
||||
}
|
||||
// member function pointer
|
||||
{
|
||||
std::bind(&A_void_2::mem1, _1, _2)(A_void_2(), 3);
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
std::bind(&A_void_2::mem1, _2, _1)(3, A_void_2());
|
||||
assert(count == save_count+3);
|
||||
save_count = count;
|
||||
}
|
||||
}
|
||||
|
||||
int f_nested(int i)
|
||||
{
|
||||
return i+1;
|
||||
}
|
||||
|
||||
int g_nested(int i)
|
||||
{
|
||||
return i*10;
|
||||
}
|
||||
|
||||
void test_nested()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
assert(std::bind(f_nested, std::bind(g_nested, _1))(3) == 31);
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test_void_1();
|
||||
test_int_1();
|
||||
test_void_2();
|
||||
test_nested();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int count = 0;
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test(F f)
|
||||
{
|
||||
int save_count = count;
|
||||
f();
|
||||
assert(count == save_count + 1);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
void
|
||||
test_const(const F& f)
|
||||
{
|
||||
int save_count = count;
|
||||
f();
|
||||
assert(count == save_count + 2);
|
||||
}
|
||||
|
||||
void f() {++count;}
|
||||
|
||||
int g() {++count; return 0;}
|
||||
|
||||
struct A_void_0
|
||||
{
|
||||
void operator()() {++count;}
|
||||
void operator()() const {count += 2;}
|
||||
};
|
||||
|
||||
struct A_int_0
|
||||
{
|
||||
int operator()() {++count; return 4;}
|
||||
int operator()() const {count += 2; return 5;}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test(std::bind(f));
|
||||
test(std::bind(&f));
|
||||
test(std::bind(A_void_0()));
|
||||
test_const(std::bind(A_void_0()));
|
||||
|
||||
test(std::bind<void>(f));
|
||||
test(std::bind<void>(&f));
|
||||
test(std::bind<void>(A_void_0()));
|
||||
test_const(std::bind<void>(A_void_0()));
|
||||
|
||||
test(std::bind<void>(g));
|
||||
test(std::bind<void>(&g));
|
||||
test(std::bind<void>(A_int_0()));
|
||||
test_const(std::bind<void>(A_int_0()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
// template<Returnable R, CopyConstructible Fn, CopyConstructible... Types>
|
||||
// unspecified bind(Fn, Types...);
|
||||
|
||||
// https://llvm.org/PR16343
|
||||
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
struct power
|
||||
{
|
||||
template <typename T>
|
||||
T
|
||||
operator()(T a, T b)
|
||||
{
|
||||
return static_cast<T>(std::pow(a, b));
|
||||
}
|
||||
};
|
||||
|
||||
struct plus_one
|
||||
{
|
||||
template <typename T>
|
||||
T
|
||||
operator()(T a)
|
||||
{
|
||||
return a + 1;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
using std::placeholders::_1;
|
||||
|
||||
auto g = std::bind(power(), 2, _1);
|
||||
assert(g(5) == 32);
|
||||
assert(std::bind(plus_one(), g)(5) == 33);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<class T> struct is_bind_expression
|
||||
|
||||
#include <functional>
|
||||
#include "test_macros.h"
|
||||
|
||||
template <bool Expected, class T>
|
||||
void
|
||||
test(const T&)
|
||||
{
|
||||
static_assert(std::is_bind_expression<T>::value == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_bind_expression<T&>::value == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_bind_expression<const T>::value == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_bind_expression<const T&>::value == Expected, "");
|
||||
|
||||
#if TEST_STD_VER > 14
|
||||
static_assert(std::is_bind_expression_v<T> == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_bind_expression_v<T&> == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_bind_expression_v<const T> == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_bind_expression_v<const T&> == Expected, "");
|
||||
#endif
|
||||
}
|
||||
|
||||
struct C {int operator()(...) const { return 0; }};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test<true>(std::bind(C()));
|
||||
test<true>(std::bind(C(), std::placeholders::_2));
|
||||
test<true>(std::bind<int>(C()));
|
||||
test<false>(1);
|
||||
test<false>(std::placeholders::_2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// TESTING template<class T> struct is_bind_expression
|
||||
//
|
||||
// bind is not implemented in C++03 so nothing is a bind expression. However
|
||||
// for compatibility reasons the trait is_bind_expression should be available
|
||||
// in C++03 and it should always return false.
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
template <class T>
|
||||
void test() {
|
||||
static_assert(!std::is_bind_expression<T>::value, "");
|
||||
}
|
||||
|
||||
struct C {};
|
||||
|
||||
int main(int, char**) {
|
||||
test<int>();
|
||||
test<void>();
|
||||
test<C>();
|
||||
test<C&>();
|
||||
test<C const&>();
|
||||
test<C*>();
|
||||
test<void()>();
|
||||
test<int(*)()>();
|
||||
test<int (C::*)()>();
|
||||
test<decltype(std::placeholders::_2)>();
|
||||
|
||||
return 0;
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<class T> struct is_bind_expression;
|
||||
// A program may specialize this template for a program-defined type T
|
||||
// to have a base characteristic of true_type to indicate that T should
|
||||
// be treated as a subexpression in a bind call.
|
||||
// https://llvm.org/PR51753
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
struct MyBind {
|
||||
int operator()(int x, int y) const { return 10*x + y; }
|
||||
};
|
||||
template<> struct std::is_bind_expression<MyBind> : std::true_type {};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
auto f = [](auto x) { return 10*x + 9; };
|
||||
MyBind bindexpr;
|
||||
auto bound = std::bind(f, bindexpr);
|
||||
assert(bound(7, 8) == 789);
|
||||
}
|
||||
{
|
||||
auto f = [](auto x) { return 10*x + 9; };
|
||||
const MyBind bindexpr;
|
||||
auto bound = std::bind(f, bindexpr);
|
||||
assert(bound(7, 8) == 789);
|
||||
}
|
||||
{
|
||||
auto f = [](auto x) { return 10*x + 9; };
|
||||
MyBind bindexpr;
|
||||
auto bound = std::bind(f, std::move(bindexpr));
|
||||
assert(bound(7, 8) == 789);
|
||||
}
|
||||
{
|
||||
auto f = [](auto x) { return 10*x + 9; };
|
||||
const MyBind bindexpr;
|
||||
auto bound = std::bind(f, std::move(bindexpr));
|
||||
assert(bound(7, 8) == 789);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// struct is_placeholder
|
||||
|
||||
#include <functional>
|
||||
#include "test_macros.h"
|
||||
|
||||
template <int Expected, class T>
|
||||
void
|
||||
test(const T&)
|
||||
{
|
||||
static_assert(std::is_placeholder<T>::value == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_placeholder<T&>::value == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_placeholder<const T>::value == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_placeholder<const T&>::value == Expected, "");
|
||||
|
||||
#if TEST_STD_VER > 14
|
||||
static_assert(std::is_placeholder_v<T> == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_placeholder_v<T&> == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_placeholder_v<const T> == Expected, "");
|
||||
LIBCPP_STATIC_ASSERT(std::is_placeholder_v<const T&> == Expected, "");
|
||||
#endif
|
||||
}
|
||||
|
||||
struct C {};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
test<1>(std::placeholders::_1);
|
||||
test<2>(std::placeholders::_2);
|
||||
test<3>(std::placeholders::_3);
|
||||
test<4>(std::placeholders::_4);
|
||||
test<5>(std::placeholders::_5);
|
||||
test<6>(std::placeholders::_6);
|
||||
test<7>(std::placeholders::_7);
|
||||
test<8>(std::placeholders::_8);
|
||||
test<9>(std::placeholders::_9);
|
||||
test<10>(std::placeholders::_10);
|
||||
test<0>(4);
|
||||
test<0>(5.5);
|
||||
test<0>('a');
|
||||
test<0>(C());
|
||||
|
||||
return 0;
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <functional>
|
||||
|
||||
// template<class T> struct is_placeholder;
|
||||
// A program may specialize this template for a program-defined type T
|
||||
// to have a base characteristic of integral_constant<int, N> with N > 0
|
||||
// to indicate that T should be treated as a placeholder type.
|
||||
// https://llvm.org/PR51753
|
||||
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
struct My2 {};
|
||||
template<> struct std::is_placeholder<My2> : std::integral_constant<int, 2> {};
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
auto f = [](auto x) { return 10*x + 9; };
|
||||
My2 place;
|
||||
auto bound = std::bind(f, place);
|
||||
assert(bound(7, 8) == 89);
|
||||
}
|
||||
{
|
||||
auto f = [](auto x) { return 10*x + 9; };
|
||||
const My2 place;
|
||||
auto bound = std::bind(f, place);
|
||||
assert(bound(7, 8) == 89);
|
||||
}
|
||||
{
|
||||
auto f = [](auto x) { return 10*x + 9; };
|
||||
My2 place;
|
||||
auto bound = std::bind(f, std::move(place));
|
||||
assert(bound(7, 8) == 89);
|
||||
}
|
||||
{
|
||||
auto f = [](auto x) { return 10*x + 9; };
|
||||
const My2 place;
|
||||
auto bound = std::bind(f, std::move(place));
|
||||
assert(bound(7, 8) == 89);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <functional>
|
||||
|
||||
// placeholders
|
||||
// The placeholders are constexpr in C++17 and beyond.
|
||||
// libc++ provides constexpr placeholders in C++11 and beyond.
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
template <class T>
|
||||
void
|
||||
test(const T& t)
|
||||
{
|
||||
// Test default constructible.
|
||||
T t2;
|
||||
((void)t2);
|
||||
// Test copy constructible.
|
||||
T t3 = t;
|
||||
((void)t3);
|
||||
static_assert(std::is_nothrow_copy_constructible<T>::value, "");
|
||||
static_assert(std::is_nothrow_move_constructible<T>::value, "");
|
||||
}
|
||||
|
||||
#if TEST_STD_VER >= 11
|
||||
constexpr decltype(std::placeholders::_1) default1{};
|
||||
constexpr decltype(std::placeholders::_2) default2{};
|
||||
constexpr decltype(std::placeholders::_3) default3{};
|
||||
constexpr decltype(std::placeholders::_4) default4{};
|
||||
constexpr decltype(std::placeholders::_5) default5{};
|
||||
constexpr decltype(std::placeholders::_6) default6{};
|
||||
constexpr decltype(std::placeholders::_7) default7{};
|
||||
constexpr decltype(std::placeholders::_8) default8{};
|
||||
constexpr decltype(std::placeholders::_9) default9{};
|
||||
constexpr decltype(std::placeholders::_10) default10{};
|
||||
|
||||
constexpr decltype(std::placeholders::_1) cp1 = std::placeholders::_1;
|
||||
constexpr decltype(std::placeholders::_2) cp2 = std::placeholders::_2;
|
||||
constexpr decltype(std::placeholders::_3) cp3 = std::placeholders::_3;
|
||||
constexpr decltype(std::placeholders::_4) cp4 = std::placeholders::_4;
|
||||
constexpr decltype(std::placeholders::_5) cp5 = std::placeholders::_5;
|
||||
constexpr decltype(std::placeholders::_6) cp6 = std::placeholders::_6;
|
||||
constexpr decltype(std::placeholders::_7) cp7 = std::placeholders::_7;
|
||||
constexpr decltype(std::placeholders::_8) cp8 = std::placeholders::_8;
|
||||
constexpr decltype(std::placeholders::_9) cp9 = std::placeholders::_9;
|
||||
constexpr decltype(std::placeholders::_10) cp10 = std::placeholders::_10;
|
||||
#endif // TEST_STD_VER >= 11
|
||||
|
||||
void use_placeholders_to_prevent_unused_warning() {
|
||||
#if TEST_STD_VER >= 11
|
||||
((void)cp1);
|
||||
((void)cp2);
|
||||
((void)cp3);
|
||||
((void)cp4);
|
||||
((void)cp5);
|
||||
((void)cp6);
|
||||
((void)cp7);
|
||||
((void)cp8);
|
||||
((void)cp9);
|
||||
((void)cp10);
|
||||
((void)default1);
|
||||
((void)default2);
|
||||
((void)default3);
|
||||
((void)default4);
|
||||
((void)default5);
|
||||
((void)default6);
|
||||
((void)default7);
|
||||
((void)default8);
|
||||
((void)default9);
|
||||
((void)default10);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
use_placeholders_to_prevent_unused_warning();
|
||||
test(std::placeholders::_1);
|
||||
test(std::placeholders::_2);
|
||||
test(std::placeholders::_3);
|
||||
test(std::placeholders::_4);
|
||||
test(std::placeholders::_5);
|
||||
test(std::placeholders::_6);
|
||||
test(std::placeholders::_7);
|
||||
test(std::placeholders::_8);
|
||||
test(std::placeholders::_9);
|
||||
test(std::placeholders::_10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user