Re: boost::tuple with uniform types
On Aug 5, 8:15 am, Alex Vinokur <ale...@users.sourceforge.net> wrote:
Here is some tuple (triple in this case) with uniform types (for
instance, double):
boost::tuple<double, double, double> t;
Is there any way (in boost::tuple) to define such tuples something
like
uniform_tuple <3, double> t; ?
Not inherently, but you could use your own template typedefs:
template<int count, typename T> struct uniform_tuple;
template<typename T> struct uniform_tuple<2,T> { typedef
boost::tuple<T,T> type; };
template<typename T> struct uniform_tuple<3,T> { typedef
boost::tuple<T,T,T> type; };
template<typename T> struct uniform_tuple<4,T> { typedef
boost::tuple<T,T,T,T> type; };
// etc.
Then you use it like:
uniform_tuple<3,double>::type t;
You could play with Boost's MPL type lists and such to make it more
generic and have the preprocessor generate the redundant code, but
that may be overkill for what you want to do (not to mention beyond
the scope of this group, unlike tuple talk). Also the next version of
the standard will make template typedefs of thing a little prettier,
but you'll have to live with the ugliness for now.
Cheers! --M