小编san*_*rey的帖子

C++ Lambda没有operator()

我需要一种方法来计算函数的参数类型,所以我编写了一个closure_traits类,如下所示,受到启发是否有可能找出lambda的参数类型和返回类型?.

但是,当我尝试将它应用于一个简单的lambda时,我得到'operator()'不是'(lambda type)'的成员的错误.但是,根据cppreference,lambda确实有一个operator().我也尝试过使用std :: function,并得到了相同的错误.我想我不确定出了什么问题,任何帮助都会非常感激.

#include<type_traits> 
#include<tuple>                                                                           
#include<utility> 
#include<iostream>                                                                                                     

/* For generic types use the type signature of their operator() */                                                     
template <typename T>                                                                                      
struct closure_traits : public
                        closure_traits<decltype(&T::operator())> {};                                        

/* Otherwise, we do a template match on a function type. */
template <typename ClassType, typename ReturnType, 
          typename... ArgTypes>                                                  
struct closure_traits<ReturnType (ClassType::*) (ArgTypes... args)>                                                  
{
    using arity = std::integral_constant<std::size_t,
                                         sizeof...(ArgTypes)>;                                              
    using Ret = ReturnType;                                  

    /* The argument types will be the same as the types of the 
     * …
Run Code Online (Sandbox Code Playgroud)

c++ lambda templates functional-programming c++14

9
推荐指数
1
解决办法
666
查看次数

标签 统计

c++ ×1

c++14 ×1

functional-programming ×1

lambda ×1

templates ×1