名前空間
変種
操作

std::default_sentinel_t, std::default_sentinel

From cppreference.com
 
 
イテレータライブラリ
イテレータのコンセプト
イテレータのプリミティブ
アルゴリズムのコンセプトとユーティリティ
間接呼び出し可能コンセプト
共通アルゴリズム要件
(C++20)
(C++20)
(C++20)
ユーティリティ
(C++20)
イテレータアダプタ
default_sentinel_tdefault_sentinel
(C++20)(C++20)
Rangeアクセス
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
ヘッダ <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 から読み取る入力イテレータ
(クラステンプレート) [編集]
範囲の終端までの距離を追跡するイテレータアダプタ
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)