【发布时间】:2023-01-25 04:08:02
【问题描述】:
以下作品
#include <vector>
#include <ranges>
int main() {
auto view = std::vector<int>{0,1,2,3,4};
auto s = std::span{view.begin(), view.end()};
std::vector test(view.begin(), view.end());
}
但这不
#include <vector>
#include <ranges>
int main() {
auto view = std::ranges::iota_view{0, 1000};
auto s = std::span{view.begin(), view.end()};
std::vector test(view.begin(), view.end());
}
问题是我有一些通用代码,我想在其中向它发送一个范围,并且创建跨越该范围。我试过发送矢量,没问题。 iota 的结果失败了。
template <typename TRange>
requires std::ranges::random_access_range<TRange>
void Foo(TRange const & r)
{
// The algorithm starts with a full span and then partitions
auto s = std::span(r.begin(), r.end());
}
代码是从 boost 移植过来的,在那里我会使用 boost::make_iterator_range 但我猜这在标准库中被 std::span 取代了。这是正确的吗?
【问题讨论】: