私はコンパイルの問題に苦労しており、問題を小さなコードセグメントに縮小することができました。不完全な型の呼び出し演算子のdecltypeのための特別な振る舞い
ステージを設定するには、基本メソッドが派生クラスの別のものを呼び出すCRTPを実行しようとしています。問題は、末尾の戻り値の型を使用して、直接、派生クラスのメソッドに転送の型を取得することです。が派生クラスの呼び出し演算子に転送されない限り、これは常にをコンパイルできません。
これはコンパイル:
#include <utility>
struct Incomplete;
template <typename Blah>
struct Base
{
template <typename... Args>
auto entry(Args&&... args)
-> decltype(std::declval<Blah&>()(std::declval<Args&&>()...));
};
void example()
{
Base<Incomplete> derived;
}
を、これはしませんが:(注唯一の違いについてのコメント)
#include <utility>
struct Incomplete;
template <typename Blah>
struct Base
{
template <typename... Args>
auto entry(Args&&... args)
-> decltype(std::declval<Blah&>().operator()(std::declval<Args&&>()...));
// I only added this ^^^^^^^^^^^
};
void example()
{
Base<Incomplete> derived;
}
私が取得エラー:
<source>: In instantiation of 'struct Base<Incomplete>':
15 : <source>:15:22: required from here
10 : <source>:10:58: error: invalid use of incomplete type 'struct Incomplete'
-> decltype(std::declval<Blah&>().operator()(std::declval<Args&&>()...));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
があるようですDerivedクラスのdecltypeを解決する際にいくつかの特別な動作が起こります。これを説明するものが標準の中にありますか?
EDIT:メイドさらに大きな簡素化
PS:godbolt上の例をコンパイル:クラステンプレートをインスタンス化https://godbolt.org/g/St2gYC
なぜ 'std :: declval()'と書かれていませんか?私は、2番目のブロックがodrの '' Incomplete''の使用であると考えていますが、最初のブロックはそうではありません。 –
@PasserByいずれにせよ、それは同じ問題です。私はあなたの提案に変更したので、混乱は少なくなった。 –
あなたはこれを探していますか? https://stackoverflow.com/questions/7943525/is-it-possible-to-figure-out-the-parameter-type-and-return-type-of-a-lambda –