std:: default_sentinel_t, std:: default_sentinel
From cppreference.net
C++
Iterator library
| Iterator concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator primitives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Algorithm concepts and utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Indirect callable concepts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Common algorithm requirements | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Utilities | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Iterator adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定義先ヘッダ
<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_istream
(クラステンプレート) |
|
|
std::basic_streambufから読み込む入力イテレータ
std::basic_streambuf
(クラステンプレート) |
|
|
(C++20)
|
範囲の終端までの距離を追跡するイテレータアダプタ
(クラステンプレート) |