[英]Is there an std view for random access iterators, as std::span is for contiguous iterators?
Is there a standard view for random access iterators, as std::span is for contiguous iterators?是否有随机访问迭代器的标准视图,因为 std::span 用于连续迭代器?
It is a piece of cake to implement such thing, but I ask before reinvent the wheel.实现这样的事情是小菜一碟,但我在重新发明轮子之前问过。 I don't see something like that on cppreference.
我在 cppreference 上看不到类似的东西。
std::span
is a pointer and a size (or equivalently two pointers). std::span
是一个指针和一个大小(或等效的两个指针)。 It doesn't need to do type erasure.它不需要进行类型擦除。
A random_access_view
would have the overhead of type erasure, so I don't expect one to be standardised.一个
random_access_view
会有类型擦除的开销,所以我不希望一个被标准化。
Instead I would suggest a template constrained to std::ranges::random_access_range
, possibly in conjunction with std::ranges::viewable_range
if you need a view specifically.相反,我建议将模板限制为
std::ranges::random_access_range
,如果您需要专门的视图,则可能与std::ranges::viewable_range
结合使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.