本文介绍了可写的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?
推荐答案
-
copy
接受输出 iterator ,而不接受输出 range .因此,您需要在zip视图上调用begin
并将其变成迭代器. - 修复该问题后,您将遇到一个单独的问题.
zip
ping两个范围会生成一个pair
(好吧,是一个common_pair
),但是虽然两个元素的元组可以从对分配,但是不能从两个元素的元组分配对.结果,我们无法执行*zip_iterator = *data.begin()
的等效操作,并且概念检查失败.如果将data
设为pair
s的向量,则它将起作用.
copy
takes an output iterator, not an output range. So you need to callbegin
on the zip view and turn it into an iterator.- With that fixed, you run into a separate problem.
zip
ping two ranges produce apair
(well, acommon_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 makedata
a vector ofpair
s, then it would work.
这篇关于可写的zip范围是不可能的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!