Nested classes don't have significant special properties, so this is generally an easy refactor. Further, it makes it easier to ensure that SFoo doesn't depend on template parameters it shouldn't (i.e., according to the idea behind SCARY iterators - the recommendations as described in n2911: https://wg21.link/n2911 )
> but what about functions that use the depended type
> is there a way to avoid the typename in front of every type?
We can make the dependent names part of the current instantiation.
Then, we need to use the disambiguators only once, in the alias declaration.
See 'Current instantiantion': https://en.cppreference.com/w/cpp/language/dependent_name
template < int N > struct A
{
struct foo { /* ... */ };
template < typename T > struct bar { /* ... */ };
};
template < int N > struct B : A<N>
{
// dependent names foo and bar are not part of the current instantiation:
// typename and template disambiguators are required
typename A<N>::foo my_foo ;
typename A<N>::template bar<int> my_bar ;
template < typename T >
typename A<N>::foo fn( consttypename A<N>::template bar<T>& ) { return {} ; }
};
template < std::size_t N > struct C : A<N>
{
using foo = typename A<N>::foo ;
template < typename T > using bar = typename A<N>::template bar<T> ;
// dependent names foo and bar are made part of the current instantiation:
// so, typename and template disambiguators are not required any more
foo my_foo ;
bar<int> my_bar ;
template < typename T > foo fn( const bar<int>& ) { return {} ; }
};
hey thx for your helpfull answers.
I did some reading during the last days and decided to go with JLBorges Solution No 2. It works fine now. Thx for your quick help :)