iterator over boost::tuple

Experts, What is the best way to iterator over boost::tuple and return value? Example: For(int i=0;i<boost::tuples::length<T>::value;i++) { Boost_tuple_example.get<i>(); } Regards, UJ

Some boost fusion sequence magic. also a working, useful example to showcase an actual application would be helpful(for example you are not even returning a value) On 2015-07-06 08:23, Uthpal Urubail wrote:
Experts, What is the best way to iterator over boost::tuple and return value? Example: For(int i=0;i<boost::tuples::length<T>::value;i++) { Boost_tuple_example.get<i>(); } Regards, UJ _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 6/07/2015 18:23, Uthpal Urubail wrote:
Experts, What is the best way to iterator over boost::tuple and return value? Example: For(int i=0;i<boost::tuples::length<T>::value;i++) { Boost_tuple_example.get<i>(); }
I think you'll need to explain more about why you're trying to do that. Tuples are typically related data of heterogeneous types, so it typically doesn't make sense (and nor is it possible without a common base class or type erasure) to return components individually in that sort of generic fashion. Unless I'm just misinterpreting your example.

I think you'll want to look info boost fusion library for this. Since you are working with heterogneous types, you'll probably need use a template function to express what you want to do. Boost Phoenix should also help you to create a polymorphic functor to apply to each element of the tuple. Le lun. 6 juil. 2015 08:51, Gavin Lambert <gavinl@compacsort.com> a écrit :
On 6/07/2015 18:23, Uthpal Urubail wrote:
Experts, What is the best way to iterator over boost::tuple and return value? Example: For(int i=0;i<boost::tuples::length<T>::value;i++) { Boost_tuple_example.get<i>(); }
I think you'll need to explain more about why you're trying to do that.
Tuples are typically related data of heterogeneous types, so it typically doesn't make sense (and nor is it possible without a common base class or type erasure) to return components individually in that sort of generic fashion. Unless I'm just misinterpreting your example.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Uthpal Urubail <uthpal.urubail <at> altair.com> writes:
Experts, What is the best way to iterator over boost::tuple and return value? Example: For(int i=0;i<boost::tuples::length<T>::value;i++) { Boost_tuple_example.get<i>(); } Regards, UJ
If you're in C++14, Hana to the rescue! ------------------------------------------------------------------------------ #include <boost/hana/tuple.hpp> #include <string> namespace hana = boost::hana; int main() { auto xs = hana::make_tuple(1, 'x', std::string{"foobar"}); hana::for_each(xs, [](auto x) { // use x }); } ------------------------------------------------------------------------------ Regards, Louis
participants (5)
-
Gavin Lambert
-
Louis Dionne
-
Oswin Krause
-
stephane GULLAUD
-
Uthpal Urubail