Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | ranges
m (P1870R1 safe_range)
m (Text replace - "safe_(range|subrange|iterator)" to "borrowed_$1")
Line 1: Line 1:
{{cpp/ranges/title | safe_iterator_t | safe_subrange_t}}
+
{{cpp/ranges/title | borrowed_iterator_t | borrowed_subrange_t}}
 
{{cpp/ranges/navbar}}
 
{{cpp/ranges/navbar}}
  
Line 6: Line 6:
 
{{dcl | num = 1 | since = c++20 | 1 =
 
{{dcl | num = 1 | since = c++20 | 1 =
 
template<ranges::range R>
 
template<ranges::range R>
using safe_iterator_t = std::conditional_t<ranges::safe_range<R>,
+
using borrowed_iterator_t = std::conditional_t<ranges::borrowed_range<R>,
 
     ranges::iterator_t<R>, ranges::dangling>;
 
     ranges::iterator_t<R>, ranges::dangling>;
 
}}
 
}}
 
{{dcl | num = 2 | since = c++20 | 1 =
 
{{dcl | num = 2 | since = c++20 | 1 =
 
template<ranges::range R>
 
template<ranges::range R>
using safe_subrange_t = std::conditional_t<ranges::safe_range<R>,
+
using borrowed_subrange_t = std::conditional_t<ranges::borrowed_range<R>,
 
     ranges::subrange<ranges::iterator_t<R>>, ranges::dangling>;
 
     ranges::subrange<ranges::iterator_t<R>>, ranges::dangling>;
 
}}
 
}}
Line 17: Line 17:
 
{{dcl end}}
 
{{dcl end}}
  
@1@ Same as {{ltt|cpp/ranges/iterator_t|ranges::iterator_t}} when {{tt|R}} models {{lconcept|safe_range}}, otherwise yields {{ltt|cpp/ranges/dangling|ranges::dangling}} instead.
+
@1@ Same as {{ltt|cpp/ranges/iterator_t|ranges::iterator_t}} when {{tt|R}} models {{lconcept|borrowed_range}}, otherwise yields {{ltt|cpp/ranges/dangling|ranges::dangling}} instead.
 
@2@ Similar to {{v|1}}, but it yields a specialization of {{ltt|cpp/ranges/subrange|ranges::subrange}} when the the same condition is met.
 
@2@ Similar to {{v|1}}, but it yields a specialization of {{ltt|cpp/ranges/subrange|ranges::subrange}} when the the same condition is met.
  

Revision as of 05:26, 19 February 2020

 
 
Ranges library
Range adaptors
 
Defined in header <ranges>
template<ranges::range R>

using borrowed_iterator_t = std::conditional_t<ranges::borrowed_range<R>,

    ranges::iterator_t<R>, ranges::dangling>;
(1) (since C++20)
(2) (since C++20)
1) Same as ranges::iterator_t when R models borrowed_range, otherwise yields ranges::dangling instead.
2) Similar to (1), but it yields a specialization of ranges::subrange when the the same condition is met.

These two alias templates are used by some constrained algorithms to avoid returning potentially dangling iterators or views.

See also

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