Familiar template syntax for generic lambdas

前端 未结 1 1771
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 05:15

For c++20 it is proposed to add the following syntax for generic lambdas p0428r2.pdf

auto f = [](          


        
1条回答
  •  隐瞒了意图╮
    2021-01-21 05:40

    The result of a lambda expression is not a function; it is a function object. That is, it is a class type that has an operator() overload on it. So this:

    auto f = []( T t ) {};
    

    Is equivalent to this:

    struct unnamed
    {
      template
      void operator()(T t) {}
    };
    
    auto f = unnamed{};
    

    If you want to explicitly provide template arguments to a lambda function, you have to call operator() explicitly: f.operator()