
"Mark Rodgers" <mark.rodgers@cadenza.co.nz> wrote in message news:002601c41836$33148560$0100a8c0@cadenza.co.nz...
Well I think in terms of code, and it really is quite simple IMHO:
Traits look like this:
template< typename T > class SomeTraits { // Stuff that tells us about T };
and Policies look like this
template< typename Policy > class SomeThing { // Delegates some behaviour to Policy };
IOW, traits are class templates and policies are template parameters so there really can't be any confusion between the two. So in the case std::basic_string
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > class basic_string {
"char_traits" is a traits class template but "traits" is actually a policy template parameter.
That's is namely the problem I have with basic_string design. Trais class is used as policy. Actually it's even worse - char_traits contain partially functionality that may belong to some kind of policy (for example comparison method). IMO it should be separated.
It is quite reasonable for specialisations of traits templates to be used as arguments to policy parameters, which is exactly what happens when we write
std::basic_string< char,std::char_traits<char> >
But I don't think there is anything in basic_string that requires the template argument to be a specialisation of a class template. I think it would be quite legitimate to write
class MyFunkyCharBehaviour { /*...*/ }; typedef std::basic_string<char,MyFunkyCharBehaviour> MyFunkyString;
Exactly, so we could use complete different class that will define different trait values. And this is not good IMO.
so the "traits" parameter is indeed misnamed.
However std::char_traits is most definitely a traits template and doesn't *have* to be used as a policy. In fact std::basic_string could have been written to exclusively use char_traits *instead* of a policy.
IMO it should've been.
Mark
Gennadiy.