Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | ranges
(P1252R2 safe_iterator_t, safe_subrange_t)
 
m (std::)
Line 6: Line 6:
 
{{dcl | num = 1 | since = c++20 | 1 =
 
{{dcl | num = 1 | since = c++20 | 1 =
 
template<Range R>
 
template<Range R>
using safe_iterator_t = conditional_t<__ForwardingRange<R>,
+
using safe_iterator_t = std::conditional_t<__ForwardingRange<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<Range R>
 
template<Range R>
using safe_subrange_t = conditional_t<__ForwardingRange<R>,
+
using safe_subrange_t = std::conditional_t<__ForwardingRange<R>,
 
     ranges::subrange<ranges::iterator_t<R>>, ranges::dangling>;
 
     ranges::subrange<ranges::iterator_t<R>>, ranges::dangling>;
 
}}
 
}}

Revision as of 08:43, 9 May 2019

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

using safe_iterator_t = std::conditional_t<__ForwardingRange<R>,

    ranges::iterator_t<R>, ranges::dangling>;
(1) (since C++20)
template<Range R>

using safe_subrange_t = std::conditional_t<__ForwardingRange<R>,

    ranges::subrange<ranges::iterator_t<R>>, ranges::dangling>;
(2) (since C++20)
1) Same as ranges::iterator_t when R models exposition-only concept __ForwardingRange, 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]