相关疑难解决方法(0)

推导函数指针返回类型

我认为代码会更好地说明我的需求:

template <typename F>
struct return_type
{
  typedef ??? type;
};
Run Code Online (Sandbox Code Playgroud)

以便:

return_type<int(*)()>::type -> int
return_type<void(*)(int,int)>::type -> void
Run Code Online (Sandbox Code Playgroud)

我知道的decltyperesult_of,但他们需要有传递的参数.我想从单个模板参数推断出函数指针的返回类型.我无法将返回类型添加为参数,因为这正是我想要隐藏的内容......

我知道有一个提升解决方案,但我不能使用它,并试图从提升中挖掘它导致了一个壮观的失败(通常如此).

欢迎使用C++ 11解决方案(只要VS2012支持).

c++ function-pointers c++11

10
推荐指数
1
解决办法
3554
查看次数

用于返回函数的Decltype

我正在创建一个模板化的类,它是任何迭代器的包装器.我这样做运营商*:

template <typename T>
class MyIterator {
public:
    //...
    decltype(*T()) operator*() {
    //...
    }
}
Run Code Online (Sandbox Code Playgroud)

我给decltype一个调用给类T的operator*,它甚至可以工作,但是如果T没有默认构造函数它就不会工作.

有没有找到函数/方法的返回类型?

c++ templates decltype c++11

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

标签 统计

c++ ×2

c++11 ×2

decltype ×1

function-pointers ×1

templates ×1