Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2004-04-01 20:22:42

"David Abrahams" <dave_at_[hidden]> wrote in message
> "Rozental, Gennadiy" <gennadiy.rozental_at_[hidden]> writes:
> >> > 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:
> >>
> >> mpl::apply_if<
> >> is_pointer<X>, remove_pointer<X>, add_reference<X>
> >> >
> >
> > What he meant, I think, is "never passed as a template parameter
> > with primary type"
> I don't know what "primary type" means here.

X in example above. Actually you may say that even my rephrasing isn't
correct. One could always says

mpl::apply_if<is_pointer<X>, X, "something else" >

Let me try this way:

For any type "T" listed in template definition no class that specify trait
of the type "T" is used in a same template parameter list.

> >> 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.
> >
> > Could you please rephrase. It's a bit unclear.
> Technically one can never say "class template foo is a traits
> template" or "class template foo is a policy" without examining how
> it's used. There's no fundamental reason that the same class template
> can't be used in both ways, so for any given class template, there may
> be no either/or answer.

Well, technically you maybe right, though it's quite difficult to imagine an
example of that. But still trait is entity that *define* compile time
mapping of type to some kind of value, which maybe numaric value, another
type or any other more complex thing (including something that may defines
behavior). You may use it as a template parameter (not quite as a policy
though in majority of the cases). Like in example above. Here we are using
type trait as a selector. But is_pointer is still a trait class. Would you
advokate a design that supply is_pointer along with type it applied to as a
template parameters?

template<typename T, typename TIsPointer>
struct my_container {...};

template<typename T>
struct C {
    my_container<T,is_pointer<T> > storage;

So, could we say that is_pointer defines a trait?



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