Article

On wrapping a callable in a lambda that just calls it with the same parameters

The Old New Thing ·The Old New Thing ·Published 2026-08-19 ·5 min read

This article discusses the unnecessary complexity of wrapping a lambda inside another lambda when the inner lambda can be called directly. It explains that a lambda is just syntactic sugar for a class with a function call operator, and highlights the importance of understanding this to avoid unnecessary indirection.

From the article

Suppose you have a function that accepts a lambda and wants to use it when calling another function. I’ve seen people wrap the lambda inside another lambda:

template<typename Lambda> bool Widget::QueueToWorkerThread(Lambda&& lambda) { CreateWorkerThreadIfNeeded(); return m_dispatcherQueue.TryEnqueue( [lambda = std::forward<Lambda>(lambda)]() { lambda(); } ); } But there’s no point in wrapping a lambda inside another lambda if you are just calling the inner lambda with the same parameters as the outer one. You can use the inner lambda’s function call operator directly.

template<typename Lambda> bool Widget::QueueToWorkerThread(Lambda&& lambda) { CreateWorkerThreadIfNeeded(); return m_dispatcherQueue.TryEnqueue( std::forward<Lambda>(lambda) ); } My guess is that some people don’t realize…


Share this resource


Discovered 2026-08-21 Source The Old New Thing Archive 2026-08 →