Storing a callable
Instead of std::function, we can use etl::delegate – a callable holder from the ETL. One of its limitations is it doesn’t work with capturing lambdas. This may affect the code expressiveness, but it provides us with equivalent functionality that allows us to capture different callables. This code demonstrates using the class template task with etl::delegate:
using callable_etl = etl::delegate<void()>;
using task_etl = task<callable_etl>;
class test {
public:
test(int x) : x_(x) {}
void print() const {
printf("This is a test, x = %d.\r\n", x_);
}
void static print_static() {
printf("This is a static method in test.\r\n");
}
private:
int x_ = 0;
};
test test_1(42);
task_etl task_member_fun(callable_etl::create<test, &test::print>
(test_1));
task_member_fun...