Embedding and recovering the type information in generic lambda expressions.
Emulating templated generic lambda expressions
by Krzysztof Ostrowski
From the article:
One of the greatest advantages of lambda expressions is their locality. It is really comfortable to reason about the code if the most of its parts are in the "near" scope, and the inversion of control is limited. On the other hand, optimiser's life is much easier with lambdas (they are just syntactic sugar, thus their actual structure is defined by the compiler). Moreover, lambdas' opaque mangled names can drastically reduce compile times. Parametrically polymorphic (generic) lambda expressions introduce additional flexibility in algorithm implementation and minimise maintenance work.
Paradoxically, generic lambda expressions in C++17 are somewhat too generic. That characteristic announces itself in inability to fix the lambda parameters in advance. Unlike in function templates, we cannot specify the parameter types explicitly to effectively disable template argument deduction from the passed function arguments.
Some steps towards templated generic lambdas are going to be taken in C++20. For the time being, a simple technique that emulates templated generic lambdas proposed in this article may be reused.
Add a Comment
Comments are closed.