Boost logo

Boost :

From: Douglas Gregor (dgregor_at_[hidden])
Date: 2008-01-11 08:29:14


On Thu, 2008-01-10 at 16:57 -0500, Michael Fawcett wrote:
> > Traits classes are far better than nested typedefs, because one can
> > always specialize a traits class for an existing type---even if you
> > can't modify the type because it is built-in or comes from another
> > library that you can't modify.
>
> This has always been my thinking, but to play devil's advocate, what
> about providing an adapter class around that type that you can't
> modify? To answer my own question, it provides a much larger burden
> on the user of your library (wrap all instances with wrapper type when
> using my generic algorithms vs. specializing one traits struct).

Exactly. An adapter class is always an option (whether or not the
generic algorithm uses traits), but it's a last-resort option because it
often requires more code and more maintenance than specializing traits.

> // Completely traits
> template <typename T>
> typename node_traits<T>::data_type *data(T *node)
> {
> boost::function_requires<NodeConcept>();
> return slist_node_traits<T>::data(node)
> }
>
> and, if you suggest using all traits, would Node Concept be reduced to
> simply checking to see if node_traits was fully specialized?

Using all traits is extremely hard, because so many things happen
implictly in C++---implicit conversions, copy constructions, etc.. But
yes, if you used only traits, checking for a fully specialized
node_traits (with the right signatures!) would work.

        - Doug


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