Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/ranges/borrowed iterator t"

From cppreference.com
< cpp‎ | ranges
(LWG 3551. borrowed_{iterator,subrange}_t are overspecified)
(Adjust links, qualify IDs with std:: for consistency.)
Line 15: Line 15:
 
{{dcl end}}
 
{{dcl end}}
  
If {{tt|R}} models {{lconcept|borrowed_range}}, same as {{ltt|cpp/ranges/iterator_t|ranges::iterator_t<R>}} {{v|1}} or {{ltt|cpp/ranges/subrange|ranges::subrange<ranges::iterator_t<R>>}} {{v|2}}, otherwise same as {{ltt|cpp/ranges/dangling|ranges::dangling}}.
+
@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

 
 
Ranges library
Range adaptors
 
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)
1) std::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

See also

a placeholder type indicating that an iterator or a subrange should not be returned since it would be dangling
(class) [edit]