Alien-libpanda
view release on metacpan or search on metacpan
src/panda/function_utils.h view on Meta::CPAN
return new function_caster<decltype(func.func), Ret, Args...>(func.func);
}
template <class Class, typename Ret, typename... Args>
struct method : public Ifunction<Ret, Args...>{
using Method = Ret (Class::*)(Args...);
using ifunction = Ifunction<Ret, Args...>;
method(Method method, iptr<Class> thiz = nullptr) : thiz(thiz), meth(method) {}
iptr<method> bind(iptr<Class> thiz) {
this->thiz = thiz;
return iptr<method>(this);
}
Ret operator()(Args... args) override {
return (thiz.get()->*meth)(std::forward<Args>(args)...);
}
bool equals(const AnyFunction* oth) const override {
auto moth = dynamic_cast<const method<Class, Ret, Args...>*>(oth->get_base());
t/function.cc view on Meta::CPAN
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;};
( run in 1.140 second using v1.01-cache-2.11-cpan-e1769b4cff6 )