可写的zip范围是不可能的吗

可写的zip范围是不可能的吗

本文介绍了可写的zip范围是不可能的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

以下失败:

#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

c语

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?

推荐答案

  1. copy接受输出 iterator ,而不接受输出 range .因此,您需要在zip视图上调用begin并将其变成迭代器.
  2. 修复该问题后,您将遇到一个单独的问题. zip ping两个范围会生成一个pair(好吧,是一个common_pair),但是虽然两个元素的元组可以从对分配,但是不能从两个元素的元组分配对.结果,我们无法执行*zip_iterator = *data.begin()的等效操作,并且概念检查失败.如果将data设为pair s的向量,则它将起作用.
  1. 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.
  2. With that fixed, you run into a separate problem. zipping 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 pairs, then it would work.

这篇关于可写的zip范围是不可能的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:11