Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-04-01 15:13:24

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.

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.
A traits class never has state.

Policy - A class template passed to other templates for the
purpose of providing a named grouping of metainformation,
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

Rob Stewart                           stewart_at_[hidden]
Software Engineer           
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at, gregod at, cpdaniel at, john at