//! generate fns that allow you to create and initialize a vector in //! one step /*! for i in (1,10) generates an function taking i arguments (const T&) that looks like the following (e.g. i==3): \code template <typename T> std::vector<T> make_vector(const T& el1_, const T& el2_, const T& el3_) { std::vector<T> v; v.push_back(el1_); v.push_back(el2_); v.push_back(el3_); return v; } \endcode ...so you'd use it like this: std:vector<int> v = tt_generic_ns::make_vector(22, 17, -5) */ #include "boost/preprocessor.hpp" // make a single ivector overload of rank N #define XX_GENER_IVECTOR(N,P) \ template <typename T> std::vector<T> \ make_vector(BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(N),const T& el) ) \ { \ std::vector<T> rv; \ /* do all the push_back()'s */ \ BOOST_PP_REPEAT(BOOST_PP_INC(N),XX_GENER_IVECTOR_REP_BODY,el) \ return rv; \ } // expands to the code for all the push_backs for an ivector of rank I #define XX_GENER_IVECTOR_REP_BODY(I,P) \ rv.push_back(BOOST_PP_CAT(P,I)); // actually generate as many of the functions as we need (10 is good) uses // REPEAT_2ND, because other macro already uses a REPEAT in // ENUM_PARAMS BOOST_PP_REPEAT_2ND(10,XX_GENER_IVECTOR,_)