I am using GCC 7.3 with C++17 and I do not understand why this line is failing:
template <typename... Args>
using X = std::invoke_result<std::tie, Args...>::type;
Error is:
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’
It's all in the error message:
note: expected a type, got 'std::tie'
invoke_result
is a metafunction that takes a bunch of types . std::tie()
is a function template - it's not a type. And it's not even an object, so you cannot do invoke_result<decltype(std::tie), Args...>
either.
What invoke_result
gives you is one syntax that works for all kinds of callables. But you don't need that with std::tie
- it's a function template, so you can just directly invoke it in an unevaluated context:
template <typename... Args>
using X = decltype(std::tie(std::declval<Args>()...));
Note: Unless you really, specifically need the metafunction itself, just always use the _t
alias. That is, std::invoke_result_t<...>
rather than std::invoke_result<...>::type
. The latter is wrong anyway, since you're missing the typename
keyword - and the alias obviates that need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.