The following is failing:
#include <range/v3/view.hpp>
#include <range/v3/view/zip.hpp>
#include <range/v3/utility/iterator.hpp>
// ...
std::vector< std::tuple<int, std::string> > const data{
{1,"a"},
{2,"b"},
{3,"c"}
};
std::vector<int> vi(data.size());
std::vector<std::string> vs(data.size());
using namespace ranges;
copy(data, view::zip(vi,vs) ); // error
clang says
No matching function for call to object of type 'const
ranges::v3::with_braced_init_args<ranges::v3::copy_fn>'
Assuming this is by design, why?
And, how can I do this obvious thing with ranges?
copy
takes an output iterator , not an output range . So you need to call begin
on the zip view and turn it into an iterator.zip
ping two ranges produce a pair
(well, a common_pair
), but while tuples of two elements are assignable from pairs, pairs are not assignable from tuples of two elements. As a result, we can't do the equivalent of *zip_iterator = *data.begin()
, and the concept check fails. If you make data
a vector of pair
s, then it would work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.