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

▼ Show 1 Answer

0 votes

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.

Learn More with Madanswer

Related questions

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