別のテンプレート内にネストされたクラス テンプレートがあります。部分的に特殊化するのは簡単ですtemplate< … >
。親の中で別のブロックを宣言するだけです。
ただし、すべてのローカル テンプレート引数を指定する別の部分的な特殊化が必要です。これにより、明示的な特殊化になります。明示的な特殊化は、何らかの理由で、名前空間のスコープにある必要があります。親クラスの外で宣言するには、親を指定する必要があります。これには、空でないテンプレート引数リストが必要です。これは、部分的な特殊化を意味します。私が行っているのは部分的な特殊化であり、任意の外側のスコープで動作するはずです。しかし、GCC と Comeau はどちらも、部分特殊化の仮引数を使用して、親の指定でテンプレート パラメーターを識別できません。
template< class X > struct A {
template< class Y > struct B; // initial declaration OK
template< class Z >
struct B< A< Z > > {}; // partial OK as long as there's a local arg
template<> // ERROR: this syntax triggers explicit specialization
struct B< int > {};
};
template<> // ERROR: can't nest template<>s here (why?)
template< class X > // ERROR: can't deduce X from type of A<X>::B<int> (why?)
struct A< X >::B< int > {};
(動作しないコードはすべて残しました。意味を理解するために適切にコメントしてください。)