write to a zipped back inserted ranges

2019-08-28 09:15发布

问题:

A close cousin of this other question, but with back_inserter:

#include <range/v3/view.hpp>
#include <range/v3/view/zip.hpp>
#include <range/v3/utility/iterator.hpp>

// ...

std::vector< std::tuple<int, std::string, double> > const data{
   {1,"a", 3.14},
   {2,"b", 42.0},
   {3,"c"}
};
std::vector<int> vi;
std::vector<std::string> vs;
std::vector<double> vd;

using namespace ranges;
copy(data,  view::zip(
   back_inserter(vi),
   back_inserter(vs),
   back_inserter(vd)) );

This is obviously an error because back_inserter() is an iterator, and zip is expecting a range. But how to accomplish zipping into a back inserted ranges?

标签: c++ range-v3