[Tuple] augment_tuple, patch, or whatever... maybe MPL?

Dear all, Is there any function in Boost.Tuple which works like this for n-tuples for any given n? template<typename T1, typename T2, typename T3> tuples::tuple<T1, T2, T3> augment_tuple(tuples::tuple<T1, T2> tup, T3 t3) { return tuples::make_tuple(tup.get<0>(), tup.get<1>(), t3); } (Obviously, here n == 2.) The purpose of this augment_tuple (or, patch, or whatever) is to take an n-tuple and a new element and patch the new element to the end of the n-tuple in order to get a (n + 1)-tuple. Repetitive code which can produce enough overloads for a large enough n is of course trivial. I'm wondering whether MPL has a utility which can automated this though? TIA, --Hossein

On Tue, Nov 23, 2010 at 12:05 PM, Hossein Haeri <powerprogman@yahoo.com>wrote:
Dear all,
Is there any function in Boost.Tuple which works like this for n-tuples for any given n?
template<typename T1, typename T2, typename T3> tuples::tuple<T1, T2, T3> augment_tuple(tuples::tuple<T1, T2> tup, T3 t3) { return tuples::make_tuple(tup.get<0>(), tup.get<1>(), t3); }
(Obviously, here n == 2.) The purpose of this augment_tuple (or, patch, or whatever) is to take an n-tuple and a new element and patch the new element to the end of the n-tuple in order to get a (n + 1)-tuple. Repetitive code which can produce enough overloads for a large enough n is of course trivial. I'm wondering whether MPL has a utility which can automated this though?
Completely off the cuff, since a tuple is more-or-less a fusion vector, and a fusion vector has push_back, I'd look there for a solution. (I'm sure a proper expert will be along in minute.) - Rob.

On Tue, Nov 23, 2010 at 12:05 PM, Hossein Haeri <powerprogman@yahoo.com>wrote:
Dear all,
Is there any function in Boost.Tuple which works like this for n-tuples for any given n?
template<typename T1, typename T2, typename T3> tuples::tuple<T1, T2, T3> augment_tuple(tuples::tuple<T1, T2> tup, T3 t3) { return tuples::make_tuple(tup.get<0>(), tup.get<1>(), t3); }
(Obviously, here n == 2.) The purpose of this augment_tuple (or, patch, or whatever) is to take an n-tuple and a new element and patch the new element to the end of the n-tuple in order to get a (n + 1)-tuple. Repetitive code which can produce enough overloads for a large enough n is of course trivial. I'm wondering whether MPL has a utility which can automated this though?
I think this is what you need. Since Boost.Tuple can be a conforming ForwardSequence (with the appropriate header), this does exactly what you want. http://www.boost.org/doc/libs/1_43_0/libs/fusion/doc/html/fusion/algorithm/t... - Rob.

Yup. Thanks! :) --- On Tue, 23/11/10, Robert Jones <robertgbjones@gmail.com> wrote: From: Robert Jones <robertgbjones@gmail.com> Subject: Re: [Boost-users] [Tuple] augment_tuple, patch, or whatever... maybe MPL? To: boost-users@lists.boost.org Date: Tuesday, 23 November, 2010, 13:21 On Tue, Nov 23, 2010 at 12:05 PM, Hossein Haeri <powerprogman@yahoo.com> wrote: Dear all, Is there any function in Boost.Tuple which works like this for n-tuples for any given n? template<typename T1, typename T2, typename T3> tuples::tuple<T1, T2, T3> augment_tuple(tuples::tuple<T1, T2> tup, T3 t3) { return tuples::make_tuple(tup.get<0>(), tup.get<1>(), t3); } (Obviously, here n == 2.) The purpose of this augment_tuple (or, patch, or whatever) is to take an n-tuple and a new element and patch the new element to the end of the n-tuple in order to get a (n + 1)-tuple. Repetitive code which can produce enough overloads for a large enough n is of course trivial. I'm wondering whether MPL has a utility which can automated this though? I think this is what you need. Since Boost.Tuple can be a conforming ForwardSequence (with the appropriate header), this does exactly what you want. http://www.boost.org/doc/libs/1_43_0/libs/fusion/doc/html/fusion/algorithm/t... - Rob. -----Inline Attachment Follows----- _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Hossein Haeri
-
Robert Jones