Boost logo

Boost :

From: Robert Bell (belvis_at_[hidden])
Date: 2004-04-02 14:07:47

Andy Little wrote:
> "David Abrahams" <dave_at_[hidden]> wrote in message
>>"Gennadiy Rozental" <gennadiy.rozental_at_[hidden]> writes:
>>>>A trait is a part of the definition of an entity.
>>>That's right.
>>Absolutely not. A key trait of traits is that they're non-intrusive.
>>They create an association with that can be defined *after* the type
>>argument is defined.
> Surely a trait is *part of the *definition* * of an *entity* in a wider
> sense.
> (perhaps *definition* has wrong connotations)

Perhaps. It seems that the crucial distinction is that an entity's
definition is complete without the trait; traits are not part of the
definition of an entity, they add on to what the program can know (or
do) with the entity.

Using phrases like "a trait is part of the definition of an entity"
confuses the issue because of the use of the word "definition".

class Foo {
// Foo completely defined here

template<typename T>
struct traits {
// typedefs, etc.

traits<Foo> doesn't change the definition of Foo. It doesn't even extend
the definition of Foo.

void F(Foo& x)
// no mention of traits<Foo> anywhere

All of x's behavior in F() is completely determined by Foo's definition,
and not affected by traits<Foo> at all.

> A type declaration may be *one part * of a larger *entity* including it and
> (for example) its operations, traits are parts of the wider entity too.
> traits mechanism is one mechanism for associating parts of the wider
> entity. (Another is function params via ADL etc)
> But the root of the problem/thread is exactly what is a trait , or traits
> and what is a policy. ie to try to come up with an ambiguous specification
> of the word trait ,traits and policy in a C++ context.
> A trait for an entity is used to describe a feature of the entity, usually
> by parameterising the entity or some type involved in the entity via a
> traits mechanism.
> (The traits mechanism associates an entity (usually a type) with a
> particular family of traits ).
> A policy customises (part of) an entity, usually by providing an
> (alternative) implementation of (some) functionality of the entity.

For myself, I'm leaning towards the "xxx is a traits or a policy
depending on how it's used" viewpoint. I find the

template<typename T, typename traits_or_policy = traits<T> >
class Foo {

example pretty compelling. Whether or not this is an example of good
design is a red herring; because this idiom can be misused does not
affect the point that whether traits_or_policy is used as a traits or
policy class depends on how it's used by the client of Foo.


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