From: David Abrahams (dave_at_[hidden])
Date: 2004-04-01 16:09:53
Rob Stewart <stewart_at_[hidden]> writes:
> Recent messages in the thread, "Numeric conversions lib
> comments," involve questions regarding what is a trait and what
> is a policy. I have my own ideas colored by MCD and other
> sources, but try as I might, I couldn't find any authoritative or
> explicit defintion of the terms. Considering how much they are
> bandied about here on Boost, perhaps it would be good to agree
> upon Boost definitions of the terms. That way, there is less
> room for confusion when those terms are used.
My view on "traits" is here: http://tinyurl.com/25db2
> To get the ball rolling, here are my definitions. They provide
> clear, non-overlapping concepts, which I think are important
> Trait - A class template parameterized on a single type that
> associates information with that type. A traits class,
> therefore, provides an external, named grouping of
> metainformation, behavior, or both for that type. A trait class
> is never passed as a template parameter; it's name is ubiquitous.
Whoops, can't agree there. The boost type traits are passed as
template parameters all the time:
is_pointer<X>, remove_pointer<X>, add_reference<X>
> A traits class never has state.
> Policy - A class template passed to other templates for the
> purpose of providing a named grouping of metainformation,
I think a Policy might be a non-templated class.
> behavior, or both to those templates. Because it is a template
> parameter, different policy classes can be used as desired. In
> many cases, a policy class is used as a base class.
> What do you think? I know that my definitions mean that
> std::char_traits is a policy class, despite its name, and they
> probably deviate from some other ad hoc definitions. The
> question is whether these provide sound, distinct, and defensible
> concepts that could be codified for future use at Boost (and
I think your definitions are mostly on target, but I think where you
go wrong is that traits/policies has less to do with how a template
is defined than how it's used.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk