+1 vote
in C Plus Plus by
Generic Lambda C++ 14 Feature

1 Answer

0 votes
by

When specifying lambda parameters, you’ll be able to use auto instead of a type:

auto lambda = [](auto a, auto b) { return a * b; };

In C++ pseudocode, this definition is equivalent to the following:

struct lambda1
{
    template<typename A, typename B>
    auto operator()(A a, B b) const -> decltype(a * b)
    {
        return a * b;
    }
};

auto lambda = lambda1();

So using auto for parameters effectively makes the function call operator templated. The types of the parameters will be determined using the rules for template argument deduction rather than the type inference that happens with regular auto variables.

Related questions

+1 vote
asked Jan 4, 2020 in C Plus Plus by AdilsonLima
+1 vote
asked Jan 4, 2020 in C Plus Plus by AdilsonLima
...