| ||||||||||||||||||||||
| Range primitives | |||||||
| |||||||
| Range concepts | |||||||||||||||||||
| |||||||||||||||||||
| Range factories | |||||||||
| |||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper items | |||||||||||||||||
| |||||||||||||||||
constexprauto end() requires(!/*simple-view*/<V>); | (1) | (since C++20) |
constexprauto end()const requiresranges::range<const V>; | (2) | (since C++20) |
Returns a sentinel or an iterator representing the end of thetake_view. The end of thetake_view is either one past thecountth element in the underlying range, or the end of the underlying range if the latter has less thancount elements.
Overload(1) does not participate in overload resolution ifV is asimple view (that is, ifV andconst V are views with the same iterator and sentinel types).
Contents |
(none)
The result depends on the concepts satisfied by possibly const-qualified underlying view typeBase, that isV for(1) orconst V for(2).
Letbase_ be the underlying view.
| The underlying view type satisfies ... | random_access_range | ||
|---|---|---|---|
| yes | no | ||
sized_range | yes | ranges::begin(base_)+ ranges::range_difference_t<Base_>(this->size()) | std::default_sentinel |
| no | 1)/*sentinel*/<false>{ranges::end(base_)} 2)/*sentinel*/<true>{ranges::end(base_)} | ||
#include <iostream>#include <iterator>#include <list>#include <ranges>#include <type_traits>namespace ranges= std::ranges;namespace views= std::views; int main(){constauto list1={3,1,4,1,5};constauto seq1{list1|views::take(4)}; static_assert(ranges::sized_range<decltype(seq1)> andranges::random_access_range<decltype(seq1)> andstd::is_same_v<decltype(seq1.end()), decltype(list1.end())>);for(auto it= seq1.begin(); it!= seq1.end();++it)std::cout<<*it<<' ';std::cout<<'\n'; std::list list2{2,7,1,8,2};constauto seq2{list2|views::take(4)}; static_assert(ranges::sized_range<decltype(seq2)> and notranges::random_access_range<decltype(seq2)> andstd::is_same_v<decltype(seq2.end()),std::default_sentinel_t>);for(auto it= seq2.begin(); it!=std::default_sentinel;++it)std::cout<<*it<<' ';std::cout<<'\n';}
Output:
3 1 4 12 7 1 8
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| P2393R1 | C++20 | implicit conversions between signed and unsigned integer-class types might fail | made explicit |
| returns an iterator to the beginning (public member function)[edit] | |
(C++20) | iterator adaptor that tracks the distance to the end of the range (class template)[edit] |
(C++20) | compares a sentinel with an iterator returned fromtake_view::begin (function)[edit] |