199. Lambdas and Callback Management

Question.8

A developer uses templates to accept capturing lambdas without std::function:

template<typename Callback>
void on_event(Callback cb) {
   cb(42);  // Call the callback
}

int offset = 10;
on_event([offset](int val) {
   printf("%d", val + offset); // 52
});

Why is this preferred over std::function in firmware?

Need Help? Refer to the Quick Guide below

Select Answer