allow inplace task to be called in const contexts

master
Francisco Paisana 5 years ago committed by Francisco Paisana
parent 8d1beb42bd
commit ee50ed08c2

@ -155,7 +155,7 @@ public:
return *this; 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_empty() const { return oper_ptr == oper_table_t::get_empty(); }
bool is_in_small_buffer() const { return oper_ptr->is_in_buffer; } bool is_in_small_buffer() const { return oper_ptr->is_in_buffer; }
@ -188,7 +188,7 @@ public:
private: private:
union { union {
storage_t buffer; mutable storage_t buffer;
void* ptr; void* ptr;
}; };
const oper_table_t* oper_ptr; const oper_table_t* oper_ptr;

@ -390,6 +390,13 @@ int test_inplace_task()
t2(); t2();
TESTASSERT(v == 5); 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 << "outcome: Success\n";
std::cout << "========================================\n"; std::cout << "========================================\n";
return 0; return 0;

Loading…
Cancel
Save