Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-04-07 08:37:17


From: "Gennadiy Rozental" <gennadiy.rozental_at_[hidden]>
>
> > > You seem to be arguing that
> > >
> > > template<typename T, typename U = traits<T> >
> > > class Foo { };
> > >
> > > is wrong because it blurs the distinction between traits and policies. I
> >
> > I think Gennadiy would agree that this is fine because U is a
> > policy template parameter defined to use at least a subset of
> > traits' interface.
>
> I agree. It may even theoretically be possible that Foo uses U interface
> that has nothing to do with trait<T> being the trait.
> But! It would make me very wary. Even though I admit above is possible, in
> most cases it's sign of incorrect design.

I'm not sure it warrants wariness. If Foo defines semantics for
its U policy and those semantics just happen to be fulfilled by a
traits class, what's the problem with using the traits class as
the policy argument? It doesn't mean other policy classes aren't
possible, just that there is a convenient one available in an
existing traits class.

> > If U isn't well-defined and traits becomes
> > the definition of U, even though Foo doesn't use all of traits'
> > interface, then the design of Foo is poor. That would seem to be
> > the case with std::basic_string and std::char_traits. I haven't
> > looked at the implementation with this in mind, but I'm guessing
> > that std::basic_string doesn't use all of std::char_traits
> > interface, and yet the "traits" parameter of std::basic_string
> > isn't defined separately.
>
> I am not sure where you going with "doesn't use all of std::char_traits"
> IMO it does not matter which part if char_traits interface basic_string is
> using.. In any case it should've referred to it by name and not through
> template parameter.

I mean that std::basic_string's "traits" policy parameter may
only require a subset of what is defined in std::char_traits. If
that's the case, it is a mistake, in my mind, not to separately
document the required semantics for that policy. Thus, while
std::char_traits may fulfill the requirements of that policy, it
is a superset that should be documented separately.

Whether std::basic_string should have a policy or should just use
a traits class is another matter entirely.

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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