I'd like to implement a class like the one below with a member function template that takes a callable type F and applies it to the instance.
This compiles and runs in Visual Studio 15 but fails in clang with the error [x86-64 clang 4.0.0] error: invalid use of incomplete type 'Foo'
struct Foo
{
template<typename F>
auto applyFunctionToMe(F&& func)->decltype( func( Foo() ) )
{
return func( *this);
}
int contents;
};
int main()
{
Foo bar;
auto result = bar.applyFunctionToMe([](const Foo& f){ return f.contents;});
return result;
}
Is there a way to get this to work under Clang in C++11? Which compiler is more correct according to standard?
Aucun commentaire:
Enregistrer un commentaire