[英]std::result_of syntax kerfuffle
I have the following (CUDA) function:我有以下(CUDA)功能:
__device__ auto foo(my_class& x, my_function_ptr_type y ) {
return [gen](my_class& x) { return x.set_y(y); };
}
And I want typedef its return value's type.我想要 typedef 其返回值的类型。 I've fiddling with the std::result_of syntax, and can't get it quite right.
我摆弄 std::result_of 语法,但不能完全正确。 This won't work:
这行不通:
using foo_return_type = std::result_of<decltype(foo(my_class{}, my_function_ptr_type{nullptr}))>::type;
Nor this:也不是这个:
using foo_return_type = std::result_of<decltype(foo(my_class, my_function_ptr_type))>::type;
Nor this:也不是这个:
using foo_return_type = std::result_of<foo>::type;
What should I have as the template-argument to std::result_of
?我应该有什么作为
std::result_of
的模板参数?
Notes:笔记:
foo()
in the namespace.foo()
。std::result_of
...)std::result_of
...)You need a function pointer type and the parameter types, then combine them in the format of F(ArgTypes...)
.您需要一个函数指针类型和参数类型,然后以
F(ArgTypes...)
的格式将它们组合起来。 eg例如
using foo_return_type = std::result_of<decltype(&foo)(my_class&, my_function_ptr_type)>::type;
You can also make your own type trait, if you don't stick to std::result_of
.如果您不坚持使用
std::result_of
,您也可以创建自己的类型特征。 eg例如
template <typename F>
struct return_type_of_function {};
template <typename R, typename... Args>
struct return_type_of_function<R(Args...)> {
using type = R;
};
then然后
using foo_return_type = return_type_of_function<decltype(foo)>::type;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.