Boost logo

Boost :

From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2005-01-12 10:50:26


Arkadiy Vertleyb wrote:
> David Abrahams wrote:
>
>
>>* The way that Boost.MPL uses partial specialization on template
>>template parameters to peel apart lambda expressions and turn them into
>>metafunction classes.
>
>
> I thought I understand how it's done, but now that I am trying to apply this
> to my own problem, it seems that default template parameters may be a
> showstopper in applying this technique, at least in some compilers. For
> example if I have:
>
> template<class T> struct do_something;
>
> template<template<class> class T, class P0>
> struct do_something<T<P0> >
> {};
>
> template<template<class, class> class T, class P0, class P1>
> struct do_something<T<P0, P1> >
> {};
>
> GCC 3.4.2 can't figure out which specialization to use for, e.g.,
> std::vector. At the same time VC71 is fine with this, and chooses the one
> with 2 parameteres.
>
> Unfortunately I am unable to find my way around the MPL source to figure out
> what's really done...
>
> Can you clarify this?

MPL uses a template_arity meta-function and specializations on the arity
to work around this problem. Something like:

  template<class T, int N> struct do_something;

  template<template<class> class T, class P0>
  struct do_something<T<P0>, 1>
  {
  };

  template<template<class, class> class T, class P0, class P1>
  struct do_something<T<P0, P1>, 2>
  {
  };

  do_something<X, template_arity<X>::value>

HTH,

-- 
Daniel Wallin

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