boost::combine() packs a group of variables.
#include <vector>
#include <boost/range/combine.hpp>
int main(int argc, char** argv)
{
// The ranges mush have the same size
std::vector<int> ids = {1, 2, 3, 4};
std::vector<std::string> names = { "A", "B", "C", "D" };
std::vector<float> heights = { 1.71, 1.65, 1.80, 1.75 };
for( const auto &zipped : boost::combine(ids, names, heights) ) {
{
// tie()
int id;
std::string name;
float height;
boost::tie(id, name, height) = zipped;
std::cout << id << "," << name << "," << height << std::endl;
}
{
// get<>()
int id = boost::get<0>( zipped );
std::string name = boost::get<1>( zipped );
float height = boost::get<2>( zipped );
std::cout << id << "," << name << "," << height << std::endl;
}
}
}
Output:
1,A,1.71
1,A,1.71
2,B,1.65
2,B,1.65
3,C,1.8
3,C,1.8
4,D,1.75
4,D,1.75
Note, the boost version used in this example is 1.71.