std::ranges::borrowed_iterator_t, std::ranges::borrowed_subrange_t

来自cppreference.com
< cpp‎ | ranges
 
 
范围库
范围转换
(C++23)(C++23)    
(C++23)

悬垂迭代器处理
borrowed_iterator_t
borrowed_subrange_t

范围适配器
 
在标头 <ranges> 定义
template< ranges::range R >
using borrowed_iterator_t = /* 见下文 */;
(1) (C++20 起)
template< ranges::range R >
using borrowed_subrange_t = /* 见下文 */;
(2) (C++20 起)
1)R 实现 borrowed_range 则为 std::ranges::iterator_t<R>,否则为 std::ranges::dangling
2)R 实现 borrowed_range 则为 std::ranges::subrange<std::ranges::iterator_t<R>>,否则为 std::ranges::dangling

某些受约束算法使用这两个模板别名以避免返回潜在悬垂的迭代器或视图。

可能的实现

borrowed_iterator_t
template< std::ranges::range R >
using borrowed_iterator_t = std::conditional_t<std::ranges::borrowed_range<R>,
    std::ranges::iterator_t<R>, std::ranges::dangling>;
borrowed_subrange_t
template< std::ranges::range R >
using borrowed_subrange_t = std::conditional_t<std::ranges::borrowed_range<R>,
    std::ranges::subrange<std::ranges::iterator_t<R>>, std::ranges::dangling>;

参阅

占位类型,指示不应返回迭代器或子范围,因为它可能悬垂
(类)