【发布时间】:2020-08-25 14:31:10
【问题描述】:
这按预期工作:
#include <range/v3/all.hpp>
#include <iostream>
int main() {
auto chunklist = ranges::views::ints(1, 13) | ranges::views::chunk(4);
for (auto rng : chunklist) {
for (auto elt : rng)
std::cout << elt << " ";
std::cout << std::endl;
}
}
在屏幕上:
1 2 3 4
5 6 7 8
9 10 11 12
但如果我尝试用 ranges::copy 代替 for 循环,我会收到编译错误
auto chunklist = ranges::views::ints(1, 13) | ranges::views::chunk(4);
for (auto rng : chunklist) {
ranges::copy(rng, std::ostream_iterator<int>{std::cout, " "}); // FAIL
std::cout << std::endl;
}
编译错误相当模糊。我不会在这里给出全文,但看起来几乎所有概念都失败了:
note: constraints not satisfied
...
note: within '...' CPP_concept_bool weakly_incrementable =
...
note: within '...' CPP_concept_bool semiregular =
...
note: within '...' CPP_concept_bool default_constructible =
...
note: within '...' CPP_concept_bool constructible_from =
...
confused by earlier errors, bailing out
我正在使用带有选项的 gcc-9.3:
g++ -fconcepts --std=c++2a chunksimplified.cc
以及来自 github 的 trunk range-v3 库的顶部
我应该如何修改代码以使用显式算法而不是原始循环?
【问题讨论】: