Can the 'type' of a lambda expression be expressed?

后端 未结 4 498
小鲜肉
小鲜肉 2020-12-01 04:59

Thinking of lambda expressions as \'syntactic sugar\' for callable objects, can the unnamed underlying type be expressed?

An example:

struct gt {         


        
4条回答
  •  忘掉有多难
    2020-12-01 05:27

    In Microsoft Visual Studio at least (I haven't tried this with other compilers), and if you don't capture anything, the type seems to be a regular function pointer:

    std::string (*myFunctionPointer)(int x) = [] (int x) {
      char buffer[10];
      return std::string("Test ") + itoa(x, buffer, 10);
    };
    std::string testOutput = myFunctionPointer(123);
    

提交回复
热议问题