Familiar template syntax for generic lambdas

前端 未结 1 1769
隐瞒了意图╮
隐瞒了意图╮ 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 = []<typename T>( T t ) {};
    

    Is equivalent to this:

    struct unnamed
    {
      template<typename T>
      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()<template arguments>(parameters);.

    0 讨论(0)
提交回复
热议问题