|
Boost : |
From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-11-28 10:22:55
----- Original Message -----
From: "Hamish Mackenzie" <boost_at_[hidden]>
> On Wed, 2001-11-28 at 13:33, Vesa Karvonen wrote:
> >
> > Partial specialization, or pattern matching, can be nice at times.
However,
> > even FP people realize that pattern matching is rather inflexible.
Writing an
> > algorithm (higher order function) using pattern matching ties the
algorithm to
> > a single data structure (such as a list). There are much more effective
ways
> > to write reusable code.
> I think full specialization is broken in MPL too, does the following
> work?
>
> template< class T >
> class foo;
>
> template<>
> class foo< boost::mpl::type_list< int, float > >
> {
> };
>
> int main()
> {
> typdef boost::mpl::type_list< int > int_only;
> typdef boost::mpl::type_list< float > float_only;
>
> foo< boost::mpl::append< int_only, float_only >::sequence > x
> }
Nope. But I was thinking of a simple idiom which would help. We could make a
simple metafunction which returns the underlying cons-list if type pass a
type_list, or the identity otherwise. Top-level metafunctions which want to
take advantage of specialization could pass their arguments through this
normalizing function.
In any case, Vesa's point applies to full specialization just as to partial
specialization. It's still a pattern match, and your pattern can /only/
match type lists based on a particular underlying list node template.
-Dave
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk