Alien-libpanda
view release on metacpan or search on metacpan
t/function.cc view on Meta::CPAN
f = [&](){return a;};
REQUIRE(f() == 13);
}
TEST_CASE("function ptr comparations", "[function]") {
function<void(void)> f1_void = &void_func;
function<void(void)> f2_void = &void_func;
function<void(void)> f3_void = &void_func2;
REQUIRE(f1_void == f2_void);
REQUIRE(f1_void != f3_void);
REQUIRE(f1_void == tmp_abstract_function(&void_func));
REQUIRE(f1_void != tmp_abstract_function(&void_func2));
}
TEST_CASE("function ptr comparations covariant", "[function]") {
struct Int {
void operator()(int) {}
bool operator==(const Int&) const {
return true;
}
};
function<void(int)> f1(&func_int);
function<void(double)> f2(&func_int);
function<void(double)> f3(&func_double);
function<void(double)> f4(&func_int);
CHECK(f1 == f2);
CHECK(f1 != f3);
CHECK(f2 != f3);
CHECK(f2 == f4);
Int i;
function<void(int)> ff1(i);
function<void(double)> ff2(i);
CHECK(ff1 == ff2);
}
TEST_CASE("function covariant copy comparations", "[function]") {
bool called = false;
auto lambda = [&](int a) {
called = true;
return a;
};
function<int(int16_t)> f1 = lambda;
function<int(int)> f2(f1);
CHECK(f1 == f2);
CHECK(f2 == f1);
}
TEST_CASE("methods comparations", "[function]") {
iptr<Test> t = new Test();
auto m1 = make_function(&Test::foo, t);
auto m2 = make_method(&Test::foo);
REQUIRE(m1 != *m2);
m2->bind(t);
REQUIRE(m1 == function<void(int)>(m2));
iptr<Test> t2 = new Test();
m2->bind(t2);
REQUIRE(m1 != *m2);
auto m3 = make_method(&Test::foo2);
REQUIRE(m1 != *m3);
}
TEST_CASE("lambdas comparations", "[function]") {
int a = 10;
function<int(void)> l1 = [&](){return a;};
auto l2 = l1;
function<int(void)> l3 = [&](){return a;};
REQUIRE(l1 == l2);
REQUIRE(l1 != l3);
}
TEST_CASE("mixed function comparations", "[function]") {
int a = 10;
function<int(void)> l = [&](){return a;};
function<int(void)> f = &foo2;
iptr<Test> t = new Test();
auto m = make_function(&Test::bar, t);
REQUIRE(l != f);
REQUIRE(m != l);
REQUIRE(m != f);
}
TEST_CASE("null function comparations", "[function]") {
int a = 10;
function<int(void)> n;
function<int(void)> l = [&](){return a;};
function<int(void)> f = &foo2;
iptr<Test> t = new Test();
auto m = make_function(&Test::bar, t);
REQUIRE_FALSE(l == n);
REQUIRE_FALSE(f == n);
REQUIRE_FALSE(m == n);
REQUIRE_FALSE(n == l);
REQUIRE_FALSE(n == f);
REQUIRE_FALSE(n == m);
}
TEST_CASE("functors comparations", "[function]") {
function<int(int)> f1 = Test(1);
function<int(int)> f2 = Test(2);
function<int(int)> f11 = Test(1);
REQUIRE(f1 != f2);
REQUIRE(f1 == f11);
auto tmp1 = tmp_abstract_function<int, int>(Test(1)); // inited from rvalue
REQUIRE(f1 == tmp1);
}
TEST_CASE("function copy ellision", "[function]") {
Tracer::refresh();
( run in 0.491 second using v1.01-cache-2.11-cpan-e1769b4cff6 )