我正在使用GCC 7.3与C++17,我不明白为什么这一行失败:
template <typename... Args>
using X = std::invoke_result<std::tie, Args...>::type;错误是:
error: type/value mismatch at argument 1 in template
parameter list for ‘template<class _Functor, class ... _ArgTypes>
struct std::invoke_result’
using X = std::invoke_result<std::tie, Args...>::type;
note: expected a type, got ‘std::tie’发布于 2019-03-04 19:12:39
所有这些都在错误消息中:
注:预期的类型,得到‘std::tie’
invoke_result是一种采用多种类型的元功能。std::tie()是一个函数模板,它不是一种类型。而且它甚至不是一个对象,所以你也不能做invoke_result<decltype(std::tie), Args...>。
invoke_result提供给您的是一种适用于所有类型可调用的语法。但是您不需要使用std::tie --它是一个函数模板,所以您可以直接在未评估的上下文中调用它:
template <typename... Args>
using X = decltype(std::tie(std::declval<Args>()...));注意:除非您确实特别需要元功能本身,否则只需始终使用_t别名即可。也就是说,std::invoke_result_t<...>而不是std::invoke_result<...>::type。无论如何,后者是错误的,因为您缺少了typename关键字,而别名则省去了所需的内容。
https://stackoverflow.com/questions/54989993
复制相似问题