如何获得调用另一类型的函子的返回类型
How to get the return type of calling a functor with another type?
给定类型TArgument
和TFunctor
,如何使用类型为TArgument
的参数调用TFunctor
实例的结果类型?
这是我的笨拙,肮脏的解决方案:
template <class TFunctor, typename TArgument>
class ReturnValue
{
public:
typedef decltype(functor_(arguent_)) Type;
private:
static TFunctor functor_;
static TArgument arguent_;
}
但是要使其工作,TFunctor
和TArgument
都需要是默认可构造的。
有更好的方法吗?
typedef decltype(std::declval<TFunctor>()(std::declval<TArgument>())) Type;
或使用std::result_of
:
typedef typename std::result_of<TFunctor(TArgument)>::type Type;
相关文章:
- 访问者访问变体并返回不同类型时出错
- 我的模板类方法返回错误类型?
- C++ - 声明指向返回任何类型并获取任意数量参数的函数的指针
- 为什么函数名不能与返回名类型相同?
- 如何在模板中返回正确类型的数据?
- 返回派生类型时出现协变类型错误
- 当你只使用 return 时,函数返回什么类型;在 c++ 中
- 函数的返回值类型是别名 ***或 *** 布尔值
- 有没有办法改变概念中的复合需求返回的类型?
- 在C++如何从数组中提取成员并返回成员类型的数组?
- 如何在 c++ 中从 switch 语句返回不同类型的变量
- C++如何使虚拟函数返回任何类型的指针
- 返回各种类型的函数的SWIG类型映射
- 如何为返回特定类型的函数创建 SWIG 类型图
- 更改 Python 切换的 C 函数的返回值类型
- 如何修复用于根据参数返回不同类型的模板类中的错误C2679?
- 为什么我的函数不返回点类型?
- 如何返回 QVariant 类型数组
- 用 decltype 和 auto 推导出 const(返回)类型
- 元函数使用 decltype 返回元素类型