Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-10-26 15:23:20

Dear All,

I'm trying to write a metafunction rebind which, when fed a specialization
T<P1,...,Pn> of an n-ary template T, returns T<mpl::_, ...., mpl::_>. This is
straightforward if default template arguments are not considered when matching
template template parameters. (See E.g.,

    template<typename T>
    struct rebind { typedef T type; }

    template<template<typename> class T, typename P>
    struct rebind< T<P> > {
        typedef T<mpl::_> type;

    template<template<typename, typename> class T, typename P1, typename P2>
    struct rebind< T<P1, P2> > {
        typedef T<mpl::_, mpl::_> type;


On GCC 3.4.1 (and I assume earlier versions too) this leads to ambiguity errors.
To workaround this problem, I've resorted to using enable_if and
mpl::aux::template_arity, e.g.,

    template<typename T, typename Enabler = void>
    struct rebind { typedef T type; }

    template<template<typename> class T, typename P>
    struct rebind< T<P>,
                           typename mpl::aux::template_arity< T<P> >::type,
>::type >
        typedef T<mpl::_> type;

I have two questions:

1. is my analysis correct?
2. is there a better solution?

Best Regards,

Boost list run by bdawes at, gregod at, cpdaniel at, john at