Discussion:
Wrong type alias for std::invoke_result
(too old to reply)
d***@gmail.com
2018-09-25 10:21:55 UTC
Permalink
Hello,

I think there is a bug in the definition of the alias template
std::invoke_result_t, because it fails in a situation where
std::invoke_result does work:

#include <type_traits>

// Here we know that {Xs...} == {F, Args...}, but we don't want to mention
F explicitly.
template <typename... Xs>
void f (Xs...)
{
// Works perfectly.
using good = typename std::invoke_result<Xs...>::type;
// Compilation error.
using bad = std::invoke_result_t<Xs...>; // !
}

struct call
{
int operator () () const
{
return 0;
}
};

int main()
{
f(call{});
}

This means that std::invoke_result_t alias changes the "signature" of the
metafunction, breaking the correct code.
I think the implementaion should be following:

// Good.
template <typename... Xs>
using invoke_result_t = typename std::invoke_result<Xs...>::type;

but the current is ill-formed:

// Bad.
template <typename X, typename... Xs>
using invoke_result_t = typename std::invoke_result<X, Xs...>::type;
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Continue reading on narkive:
Loading...