
AMDG Robert Dailey wrote:
Hi,
Is there a way that I can provide variable length template argument lists in C++03 using boost? An example of what I want to achieve is below:
template< typename t1, typename t2, ..., typename tN > void MyFunction( t1 param1, t2 param2, ..., tN paramN ) { boost::tuple<t1, t2, ..., tN> myTuple; AnotherFunction( param1, param2, ..., paramN ); }
Right now to do this I have to create several class specializations which gets very nasty. Help is appreciated. Thanks.
The easiest way to do it is using the preprocessor: // scratch.cpp #ifndef BOOST_PP_IS_ITERATING #include <boost/preprocessor/iteration/iterate.hpp> #include <boost/preprocessor/repetition/enum_params.hpp> #include <boost/preprocessor/repetition/enum_binary_params.hpp> #include <boost/tuple/tuple.hpp> #define BOOST_PP_FILENAME_1 "scratch.cpp" #define BOOST_PP_ITERATION_LIMITS (1, 5) #include BOOST_PP_ITERATE() #else template<BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), class T)> void MyFunction(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), const T, &t)) { boost::tuple<BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), T)> myTuple; AnotherFunction(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), t)); } #endif In Christ, Steven Watanabe