可调用对象的结果类型的推导
Deduction of result type of callable
我尝试推断可调用模板参数的类型,不幸的是没有成功:
template<typename callable, typename T_out >
class A
{};
template<typename callable>
auto make_A( callable f )
{
return A<callable, typename std::result_of_t<callable> >{ f };
}
int main()
{
make_A( []( float f ){ return f;} );
}
上面的代码会导致以下错误:
error: implicit instantiation of undefined template 'std::__1::result_of<(lambda at /Users/arirasch/WWU/dev/xcode/tests/tests/main.cpp:31:11)>'
template <class _Tp> using result_of_t = typename result_of<_Tp>::type;
有谁知道怎么修理它吗?
提前感谢。
您需要将参数列表传递给std::result_of
,否则无法告诉返回类型(毕竟operator()
可以重载)。
return A<callable, std::result_of_t<callable(float)> >{ f }
(假设A<callable, std::result_of_t<callable(float)>
可以用f
构造,但本例并非如此)
相关文章:
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- ";结果类型必须是可从输入范围的值类型""构造的;创建std::vector时
- Static_cast转换为错误的数据类型,但结果仍然正确?
- 为什么'typeid(x) == typeid(y)'的计算结果为 true,其中 'x' 和 'y' 分别是 T 和 T& 类型的 id-表达式?
- 为什么 Clang 和 GCC 中两个无符号整数之和的结果类型不同
- C++ 模板结果类型
- C++,概念不适用于无符号整数作为结果类型?
- std::chrono::duration::count函数的实际结果类型是什么
- 设计自己的结果/两者之一:是否应该始终指定成功类型和错误类型
- 如何获得将两种不同类型的相乘的结果类型?
- 为什么 std::when_any 使用 std::tuple 而不是 std::vector 作为其结果类型?
- 什么是在C 中存储结果INT*的最佳数据类型
- 在不同类型的向量上使用 std::remove 的不同结果
- boost::variant 当 bool 显示为可能的类型时,会给出错误的结果
- libclang 为类型限定符给出错误的结果
- VIM:执行复杂文件类型的脚本和显示结果
- GCC 9.1 返回 void& 作为显式析构函数调用的结果类型。这是一个错误吗?
- 使用枚举确定返回结果的类型(使用宏的黑客)
- 根据运算符推断模板返回类型:结果
- 类型结果之间的意外差异