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

来自cppreference.com
< cpp‎ | ranges
 
 
 
定义于头文件 <ranges>
template< ranges::range R >
using borrowed_iterator_t = /* see below */;
(1) (C++20 起)
template< ranges::range R >
using borrowed_subrange_t = /* see below */;
(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

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

可能的实现

版本一
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>;
版本二
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>;

参阅

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