名稱空間
變體
操作

std::ranges::subrange 的推導指南

來自 cppreference.com
< cpp‎ | ranges‎ | subrange
 
 
範圍庫 (Ranges library)
範圍介面卡 (Range adaptors)
 
 
定義於標頭檔案 <ranges>
template< std::input_or_output_iterator I, std::sentinel_for<I> S >
subrange(I, S) -> subrange<I, S>;
(1) (C++20 起)
template< std::input_or_output_iterator I, std::sentinel_for<I> S >

subrange(I, S, /*make-unsigned-like-t*/<std::iter_difference_t<I>>) ->

    subrange<I, S, ranges::subrange_kind::sized>;
(2) (C++20 起)
template< ranges::borrowed_range<R> >

subrange(R&&) ->
    subrange<ranges::iterator_t<R>, ranges::sentinel_t<R>,
             (ranges::sized_range<R> ||
              std::sized_sentinel_for<ranges::sentinel_t<R>,
              ranges::iterator_t<R>>) ?

             ranges::subrange_kind::sized : ranges::subrange_kind::unsized>;
(3) (C++20 起)
template< ranges::borrowed_range<R> >

subrange(R&&, /*make-unsigned-like-t*/<ranges::range_difference_t<R>>) ->
    subrange<ranges::iterator_t<R>, ranges::sentinel_t<R>,

             ranges::subrange_kind::sized>;
(4) (C++20 起)

這些推導指南用於 std::ranges::subrange

1) 從迭代器和哨兵的型別推匯出模板實參。如果滿足 std::sized_sentinel_for<S, I>,則 subrange 是有大小的,這由預設模板實參決定。
2) 從迭代器和哨兵的型別推匯出模板實參,同時指定了範圍的大小。subrange 總是帶大小的。
3) 從範圍的型別推匯出模板實參。如果可以從範圍或其迭代器和哨兵獲得大小,則 subrange 是有大小的。
4) 從範圍的型別推匯出模板實參,同時指定了範圍的大小。subrange 總是帶大小的。

有關 /* make-unsigned-like-t */ 的定義,請參閱 make-unsigned-like-t

[編輯] 注意

構造 subrange 物件時,

  • 對於 (1,2),如果迭代器-哨兵對不表示有效範圍,則行為未定義。
  • 對於 (2,4),如果給定大小不等於範圍的大小,則行為未定義。

[編輯] 示例

[編輯] 缺陷報告

下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。

缺陷報告 應用於 釋出時的行為 正確的行為
LWG 3404 C++20 提供了無意義的 pair-like 型別推導指南 已移除