I have a class that is simply forwarding the function call to another class and I would like to be able to use std::invocable<>
on my forwarding class. But for some reason that fails... Is this what I should expect? Is there a way to work around it?
#include <type_traits>
#include <utility>
struct Foo {
constexpr int operator()( int i ) const {
return i;
}
};
struct ForwardToFoo {
template<class ...Args>
constexpr decltype(auto) operator()( Args &&...args ) const {
Foo foo;
return foo( std::forward<Args>( args )... );
}
};
int main( void ) {
// These work fine
static_assert( std::is_invocable_v<ForwardToFoo, int> == true );
static_assert( std::is_invocable_v<Foo, int> == true );
static_assert( std::is_invocable_v<Foo> == false );
// This causes a compile error
static_assert( std::is_invocable_v<ForwardToFoo> == false );
return 0;
}
Edit:
The answers so far suggest that the issue is that the last static_assert()
forces ForwardToFoo::operator()<>
to be instantiated without arguments hence triggering a compile error.
So is there a way to turn this instantiation error into a SFINAE error that can be handled without a compile error?