How to partially specialize nested class without partially specializing the nesting class?
Implementation of class C
is the same for all N
.
Implementation of C::iterator
is special for N=1
.
template<class T, int N>
class C
{
class iterator;
...
};
template<class T, int N>
class C<T, N>::iterator
{
...
};
// Partial specialization doesn't compile:
template<class T>
class C<T, 1>::iterator
{
...
};
I can partially specialize class C
for N=1
, but that's a lot of code duplication...
If you do not want to specialize whole class then just move the iterator out of class and make it template:
template<class T, int N>
class C_iterator
{
...
};
If needed make your specializations:
template<class T>
class C_iterator<T, 1>
{
...
};
Then use it in your class as iterator, if needed befriend it:
template<class T, int N>
class C
{
using iterator = C_iterator<T, N>;
friend iterator;
...
};
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments