Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2004-04-01 17:10:52


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. 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;

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.

Mark


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk