Categories

Jan 4 in C++
Q: Generic Lambda C++ 14 Feature

1 Answer

Jan 4

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.

Click here to read more about C++
Click here to read more about Insurance

Related questions

Madanswer
Jan 4 in C++
Jan 4 in C++
Nov 24 in C++
...