I am trying to use decltype in the late specified return of a member function in the CRTP base class, and with the error: invalid use of incomplete type const struct AnyOp<main()::<lambda(int)> > .
template<class Op> struct Operation { template<class Foo> auto operator()(const Foo &foo) const -> typename std::enable_if<is_foo<Foo>::value, decltype(static_cast<const Op*>(nullptr)->call_with_foo(foo))>::type { return static_cast<const Op*>(this)->call_with_foo(foo); } }; template<class Functor> struct AnyOp : Operation<AnyOp<Functor> > { explicit AnyOp(Functor func) : func_(func) {} template<class Foo> bool call_with_foo(const Foo &foo) const { //do whatever } private: Functor func_; };
I am basically trying to move the entire sfinae boiler plate to the base class, so I donβt need to repeat it for every operation I created (currently each operation has 6 different calls, and there are ~ 50 operations, so there are many repetitions with enable_if).
I tried an overload-based solution, but one of the types that can be passed is all that can be called (it could be a regular functor from C ++ 03 or C ++ 0x lambda), which I linked to std: : function, unfortunately, the overhead from std :: function, although very minimal, actually matters in this application.
Is there a way to fix what I have or is there a better solution to solve this problem?
Thanks.
c ++ c ++ 11 decltype crtp
Tim
source share