N
Narinder
Hello
I am somewhat curious about the reason for the way types in the STL
are dependant on trait classes. For example the template class
basic_string is defined as :
template<class charT,
class basic_string;
but not as:
template<class charT,
class basic_string
{
typedef traits_t<charT> traits;
typedef Allocator_t<charT> Allocator;
....
You would think (or perhaps not) that the second approach is less
error prone since it would be less likely that your traits would be
inconsistent with the char type. The only reason I can think of is
that you may have a traits class specifically for char which wouldn't
make sense for any other types and thus wouldn't need to be a
template. In that case you could always write it as template class and
use traits to activate it only for char types.
Regards
N
I am somewhat curious about the reason for the way types in the STL
are dependant on trait classes. For example the template class
basic_string is defined as :
template<class charT,
class basic_string;
but not as:
template<class charT,
class basic_string
{
typedef traits_t<charT> traits;
typedef Allocator_t<charT> Allocator;
....
You would think (or perhaps not) that the second approach is less
error prone since it would be less likely that your traits would be
inconsistent with the char type. The only reason I can think of is
that you may have a traits class specifically for char which wouldn't
make sense for any other types and thus wouldn't need to be a
template. In that case you could always write it as template class and
use traits to activate it only for char types.
Regards
N