CRTP 基本クラスのメンバー関数の指定された後期リターンで decltype を使用しようとしていますが、次のエラーが発生しています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_;
};
私は基本的に、すべての sfinae ボイラー プレートを基本クラスに移動しようとしているので、作成する操作ごとに繰り返す必要はありません (現在、各操作には 6 つの異なる呼び出しがあり、約 50 の操作があるため、かなりの量がありますenable_if を何度も繰り返します)。
オーバーロードに依存するソリューションを試しましたが、渡される可能性のある型の 1 つは、std にバインドされた呼び出し可能なもの (これは C++03 または C++0x ラムダの通常のファンクターである可能性があります) です。 :function 残念ながら、std::function からのオーバーヘッドは、ごくわずかですが、実際にはこのアプリケーションに違いをもたらします。
現在持っているものを修正する方法はありますか、またはこの問題を解決するためのより良い解決策はありますか?
ありがとう。