Boost logo

Boost Users :

Subject: Re: [Boost-users] [parameter]Boost Parameter and template template arguments
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-03-29 15:27:00


AMDG

Jesse Perla wrote:
> I have a class template with a large number of potential template parameters
> where I would like to use boost parameter.
> I understand that I can use integers with the int_<> wrapper, but is there
> any trick or design pattern to allow template template's?
> The problem is that I have class templates such as an interpolator which
> will take in a type and a dimension size, and a variety of function objects
> of the same type. If I can't use template templates, I am not sure how to
> make the design sane.
> For example, right now I have something like:
>
> template<int Dimension, class T = double, template <int Dim2, class T>
> template Interpolator = cubic_spline>
> class DPP;
>
> I don't think I can write a free function to solve the instantiation
> difficulty since many of the types are only used internally and I couldn't
> use function template argument deduction.
>

Use mpl::lamdba expressions.

First you need to wrap any templates that take
non type template parameters. For example.

template<class Dim1, class Dim>
class make_cubic_spline {
    typedef cubic_spline<Dim1::value, Dim> type;
};

Then, the default argument for Interpolator can be
make_cubic_spline<boost::mpl::_1, boost::mpl::_2>.

When you need to get a real type, use mpl::apply:

typedef boost::mpl::apply<Interpolator, mpl::int_<2>, double>::type
interpolator_instance;

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net