|
Boost : |
From: Emily Winch (emily_at_[hidden])
Date: 2001-11-26 08:38:22
> > Alternatively, could we (and should we) use named
> > template parameters as in the iterator adapters library?
> > I.e. tbd< base<B>, derived<D> >::value where tbd is a
> > name to be decided, perhaps just "are".
>
> Hmm; we'd be preparing to stuff detection of all class relationships (in
the
> future) though this one template, but I suppose that with partial
> specialization that's no problem; rather nice, actually. The workarounds I
> can think of for compilers without partial specialization are somewhat
> painful, though.
For there to be any prospect of writing code that is generic with respect to
predicates like this, you'd _have_ to detect all class relationships in the
same way, or at least write a bunch of adaptors to make that possible.
I'm not convinced that this looks sensible though:
whatever< smaller<T>, bigger<U> >::value
rather than
is_bigger< T, U >::value
And if we assume that any predicate over N types must be expressed in terms
of N names, we are forcing the writer of the aforementioned generic code to
take an extra N template parameters to represent the predicate, rather than
1. That would make the code REALLY ugly, even if we only consider N=2.
(since I can't think of an example with N > 2)
I thought of a practical use of a two-parameter type predicate passed as a
template template parameter. If you sort a tuple by the size of the objects
so the biggest ones go first, you might make it smaller (less padding
required). Clearly this would be neatly achieved by passing is_bigger as a
predicate to a sorting algorithm.
Emily.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk