c++ - How to iterate over a TR1 tuple -
being stuck in tr1 land, test program need perform operations on number of objects of specific types. have couple of tuple type definitions this:
typedef std::tr1::tuple< bool , signed char , signed short , signed int , signed long long , unsigned char , unsigned short , unsigned int , unsigned long long > integral_types; from each tuple type object created. have function templates similar this:
template<typename t> void invoke_operation_1(t& obj); these need called objects in tuple object.
how do in c++03?
you use boost::fusion if need call same templated function every object in tuple. e.g.
template<typename t> void invoke_operation_1(t& obj) { std::cout << obj << std::endl; } struct executor { template<typename t> void operator()(t& t) const { invoke_operation_1(t); } }; typedef boost::tuple< bool , signed char , signed short , signed int , signed long long , unsigned char , unsigned short , unsigned int , unsigned long long > integral_types; int main() { integral_types t(true, 0, 1, 2, 3, 4, 5, 6, 7); boost::fusion::for_each(t, executor()); return 0; }
Comments
Post a Comment