I want to use boost preprocessor to declare template classes with different template variable length, basically like what boost::function does.
#if !BOOST_PP_IS_ITERATING
#ifndef D_EXAMPLE_H
#define D_EXAMPLE_H
#include <boost/function>
#include <boost/preprocessor/iteration/iterate.hpp>
#define BOOST_PP_ITERATION_PARAMS_1 (3, (1, 2, "example.h"))
#include BOOST_PP_ITERATE()
#else
template<class T, BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class T)>
class Example
{
boost::function<T, (BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), T))> func;
};
#endif
the code above will obviously won't work because it declares the same class with different template variable length in the same header file. What I want to achieve is to include a single file and define classes with different template variable length just like boost::function.
#include "example.h"
Example<int, int, float> example1;
Example<double, int> example2;
I looked up boost::function's code but I can't figure it out how it works. Any ideas?