|
Boost Users : |
Subject: Re: [Boost-users] [MPL] Generate template instantiation ?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-10-06 14:42:43
AMDG
Olivier Tournaire wrote:
> I have a class templated on 2 arguments, e.g. :
>
> template <typename PixelType , typename NbChannels> class myClass
> {
> // ...
> };
>
> This class is in a lib, and I would like to instantiate it for all
> base type (signed char, unsigned char, int, unsigned int ...), and for
> a given number of channels. For example :
>
> <snip>
>
> And so on. Is there a way to do this without writing all possiblities.
> Maybe with the MPL ?
Use the preprocessor.
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#define MY_CLASS_INSTANTIATION(z, n, data) template class myClass<data, n>;
#define MY_CLASS_INNER_LOOP(r, data, T) BOOST_PP_REPEAT_FROM_TO(1, 10,
MY_CLASS_INSTANTIATION, T)
#define TYPES (unsigned char)(signed char)(int)(unsigned int)
BOOST_PP_SEQ_FOR_EACH(MY_CLASS_INNER_LOOP, ~, TYPES)
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