简体   繁体   中英

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?

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.

std::span is a pointer and a size (or equivalently two pointers). 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM