Difference between revisions of "cpp/ranges/borrowed iterator t"
From cppreference.com
(LWG 3551. borrowed_{iterator,subrange}_t are overspecified) |
(Adjust links, qualify IDs with std:: for consistency.) |
||
Line 15: | Line 15: | ||
{{dcl end}} | {{dcl end}} | ||
− | + | @1@ {{c|std::ranges::iterator_t<R>}} if {{tt|R}} models {{lconcept|borrowed_range}}, {{lc|std::ranges::dangling}} otherwise. | |
+ | |||
+ | @2@ {{c|std::ranges::subrange<ranges::iterator_t<R>>}} if {{tt|R}} models {{lconcept|borrowed_range}}, {{lc|std::ranges::dangling}} otherwise. | ||
These two alias templates are used by some [[cpp/algorithm/ranges|constrained algorithms]] to avoid returning potentially dangling iterators or views. | These two alias templates are used by some [[cpp/algorithm/ranges|constrained algorithms]] to avoid returning potentially dangling iterators or views. | ||
Line 23: | Line 25: | ||
|1= | |1= | ||
template< ranges::range R > | template< ranges::range R > | ||
− | using borrowed_iterator_t = std::conditional_t<ranges::borrowed_range<R>, | + | using borrowed_iterator_t = std::conditional_t<std::ranges::borrowed_range<R>, |
− | ranges::iterator_t<R>, ranges::dangling>; | + | std::ranges::iterator_t<R>, std::ranges::dangling>; |
|2= | |2= | ||
template< ranges::range R > | template< ranges::range R > | ||
using borrowed_subrange_t = std::conditional_t<ranges::borrowed_range<R>, | using borrowed_subrange_t = std::conditional_t<ranges::borrowed_range<R>, | ||
− | ranges::subrange<ranges::iterator_t<R>>, ranges::dangling>; | + | std::ranges::subrange<ranges::iterator_t<R>>, std::ranges::dangling>; |
}} | }} | ||
Line 36: | Line 38: | ||
{{dsc end}} | {{dsc end}} | ||
− | {{langlinks|es|ja|zh}} | + | {{langlinks|es|ja|ru|zh}} |
Revision as of 00:13, 13 June 2021
Defined in header <ranges>
|
||
template< ranges::range R > using borrowed_iterator_t = /* see below */; |
(1) | (since C++20) |
template< ranges::range R > using borrowed_subrange_t = /* see below */; |
(2) | (since C++20) |
2) std::ranges::subrange<ranges::iterator_t<R>> if
R
models borrowed_range
, std::ranges::dangling otherwise.These two alias templates are used by some constrained algorithms to avoid returning potentially dangling iterators or views.
Possible implementation
First version |
---|
template< ranges::range R > using borrowed_iterator_t = std::conditional_t<std::ranges::borrowed_range<R>, std::ranges::iterator_t<R>, std::ranges::dangling>; |
Second version |
template< ranges::range R > using borrowed_subrange_t = std::conditional_t<ranges::borrowed_range<R>, std::ranges::subrange<ranges::iterator_t<R>>, std::ranges::dangling>; |
See also
(C++20) |
a placeholder type indicating that an iterator or a subrange should not be returned since it would be dangling (class) |