constexpr auto begin() requires (!__SimpleView<V>); | (1) | (since C++20) |
constexpr auto begin() const requires ranges::range<const V>; | (2) | (since C++20) |
Returns an iterator to the first element of the take_view
.
Overload (1) does not participate in overload resolution if V
is a simple view (that is, if V
and const V
are views with the same iterator and sentinel types).
(none).
The result depends on the concepts satisfied by possible const-qualified underlying view type Base_
, which is V
(for overload (1)) or const V
(for overload (2)).
Let base_
be the underlying view, count_
be the number passed to the constructor (0
if default initialized).
The underlying view satisfies ... | random_access_range |
||
---|---|---|---|
yes | no | ||
sized_range | yes | ranges::begin(base_) | std::counted_iterator(ranges::begin(base_), |
no | std::counted_iterator(ranges::begin(base_), count_) |
#include <ranges> #include <iostream> #include <string_view> using namespace std::literals; int main() { static constexpr auto sv = {"∀x"sv, "∃y"sv, "ε"sv, "δ"sv}; std::cout << *std::ranges::take_view(sv, 8).begin() << '\n'; }
Output:
∀x
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 |
(C++20) | returns an iterator or a sentinel to the end (public member function) |
(C++20) | iterator adaptor that tracks the distance to the end of the range (class template) |
(C++20) | compares a sentinel with an iterator returned from take_view::begin (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/ranges/take_view/begin