allow inplace task to be called in const contexts

This commit is contained in:
Francisco Paisana 2020-04-14 13:21:35 +01:00 committed by Francisco Paisana
parent 8d1beb42bd
commit ee50ed08c2
2 changed files with 10 additions and 3 deletions

View File

@ -155,7 +155,7 @@ public:
return *this;
}
R operator()(Args&&... args) { return oper_ptr->call(&buffer, std::forward<Args>(args)...); }
R operator()(Args&&... args) const { return oper_ptr->call(&buffer, std::forward<Args>(args)...); }
bool is_empty() const { return oper_ptr == oper_table_t::get_empty(); }
bool is_in_small_buffer() const { return oper_ptr->is_in_buffer; }
@ -188,8 +188,8 @@ public:
private:
union {
storage_t buffer;
void* ptr;
mutable storage_t buffer;
void* ptr;
};
const oper_table_t* oper_ptr;
};

View File

@ -390,6 +390,13 @@ int test_inplace_task()
t2();
TESTASSERT(v == 5);
// TEST: task works in const contexts
t = l2;
auto l3 = [](const srslte::inplace_task<void()>& task) { task(); };
v = 0;
l3(t);
TESTASSERT(v == 6);
std::cout << "outcome: Success\n";
std::cout << "========================================\n";
return 0;