名稱空間
變體
操作

std::default_sentinel_t, std::default_sentinel

來自 cppreference.com
 
 
迭代器庫
迭代器概念
迭代器原語
演算法概念與工具
間接可呼叫概念
常用演算法要求
工具
迭代器介面卡
 
定義於標頭檔案 <iterator>
struct default_sentinel_t {};
(1) (C++20 起)
inline constexpr default_sentinel_t default_sentinel{};
(2) (C++20 起)
1) default_sentinel_t 是一個空類型別,用於表示範圍的末尾。它可以與知道其範圍邊界的迭代器型別(例如,std::counted_iterator)一起使用。
2) default_sentinel 是一個型別為 default_sentinel_t 的常量。

[編輯] 示例

#include <print>
#include <regex>
#include <string>
 
int main()
{
    const std::string s = "Quick brown fox.";
 
    const std::regex words_regex("[^\\s]+");
    const std::ranges::subrange words(
        std::sregex_iterator(s.begin(), s.end(), words_regex), std::default_sentinel);
 
    std::println("Found {} words:", std::ranges::distance(words));
    for (const std::smatch& match : words)
        std::println("{}", match.str());
}

輸出

Found 3 words:
Quick
brown
fox.

[編輯] 另請參閱

std::basic_istream讀取的輸入迭代器
(類模板) [編輯]
std::basic_streambuf讀取的輸入迭代器
(類模板) [編輯]
跟蹤到範圍末尾距離的迭代器介面卡
(類模板) [編輯]