namespace std { using ranges::get; }
(3) (since C++20)Provides structured binding support.
1) Obtains the iterator or sentinel from a subrange
lvalue (or a const rvalue) when N == 0 or N == 1, respectively.
2) Same as (1), except that it takes a non-const subrange
rvalue.
Overloads
(1,2)are imported into namespace
std
, which simplifies their usage and makes every
subrange
with a copyable iterator a
pair-liketype.
[edit] Parameters [edit] Return value1,2) If N is â0â, returns r.begin(). Otherwise (N is 1), returns r.end().
[edit] Example#include <array> #include <iostream> #include <iterator> #include <ranges> int main() { std::array a{1, -2, 3, -4}; std::ranges::subrange sub_a{std::next(a.begin()), std::prev(a.end())}; std::cout << *std::ranges::get<0>(sub_a) << ' ' // == *(begin(a) + 1) << *std::ranges::get<1>(sub_a) << '\n'; // == *(end(a) - 1) *std::get<0>(sub_a) = 42; // OK // *std::get<2>(sub_a) = 13; // Error: index can only be 0 or 1 }
Output:
[edit] Defect reportsThe following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 3589 C++20 overload (1) copiesbegin_
if N is â0â, but I
might not model copyable
added constraints [edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4