名前空間
変種
操作

std::match_results

From cppreference.com
< cpp‎ | regex
 
 
 
正規表現ライブラリ
クラス
(C++11)
match_results
(C++11)
アルゴリズム
イテレータ
例外
Traits
定数
(C++11)
正規表現文法
 
 
ヘッダ <regex> で定義
template<

    class BidirIt,
    class Alloc = std::allocator<std::sub_match<BidirIt>>

> class match_results;
(1) (C++11以降)
namespace pmr {

    template <class BidirIt>
    using match_results = std::match_results<BidirIt,
                              std::pmr::polymorphic_allocator<
                                  std::sub_match<BidirIt>>>;

}
(2) (C++17以降)

クラステンプレートstd::match_results は、正規表現のマッチの結果を表す文字シーケンスのコレクションを保持します。

これは特殊化されたアロケータ対応コンテナです。デフォルトで作成されるか、std::regex_iterator から取得されるか、std::regex_search または std::regex_match によって変更されるかのいずれかです。std::match_resultsstd::sub_match を保持しており、各 std::sub_match はマッチされた元の文字シーケンスへのイテレータのペアであるため、元の文字シーケンスが破棄されたり、それへのイテレータが他の理由で無効化されたりした場合に std::match_results を検査することは未定義の動作です。

std::match_result に含まれる最初の std::sub_match (インデックス 0) は、常に正規表現によってターゲットシーケンス内で行われた完全なマッチを表し、後続の std::sub_match は、正規表現内のサブ式の左括弧に対応する順序で、サブ式のマッチを表します。

std::match_results は、AllocatorAwareContainer および SequenceContainer の要件を満たしますが、コピー代入、ムーブ代入、および定数コンテナに対して定義された操作のみがサポートされ、比較関数のセマンティクスはコンテナに対して要求されるものとは異なります。

目次

[編集] 型要件

-
BidirItLegacyBidirectionalIterator の要件を満たしている必要があります。
-
AllocAllocator の要件を満たす必要があります。

[編集] 特殊化

一般的な文字シーケンス型に対するいくつかの特殊化が提供されています。

ヘッダ <regex> で定義
定義
std::cmatch std::match_results<const char*>
std::wcmatch std::match_results<const wchar_t*>
std::smatch std::match_results<std::string::const_iterator>
std::wsmatch std::match_results<std::wstring::const_iterator>
std::pmr::cmatch (C++17) std::pmr::match_results<const char*>
std::pmr::wcmatch (C++17) std::pmr::match_results<const wchar_t*>
std::pmr::smatch (C++17) std::pmr::match_results<std::string::const_iterator>
std::pmr::wsmatch (C++17) std::pmr::match_results<std::wstring::const_iterator>

[編集] メンバ型

メンバ型 定義
allocator_type アロケータ
value_type std::sub_match<BidirIt>
const_reference const value_type&
reference value_type&
const_iterator 実装定義 (基になるコンテナに依存)
iterator const_iterator
difference_type std::iterator_traits<BidirIt>::difference_type
size_type std::allocator_traits<Alloc>::size_type
char_type std::iterator_traits<BidirIt>::value_type
string_type std::basic_string<char_type>

[編集] メンバ関数

オブジェクトを構築する
(public member function) [編集]
オブジェクトを破棄する
(public member function) [編集]
内容を代入する
(public member function) [編集]
関連付けられたアロケータを返す
(public member function) [編集]
状態 (State)
結果が利用可能かどうかをチェックします。
(public member function)
Size
マッチが成功したかどうかをチェックします。
(public member function) [編集]
確立された結果状態におけるマッチの数を返します。
(public member function) [編集]
サブマッチの最大可能な数を返します。
(public member function) [編集]
要素アクセス
特定のサブマッチの長さを返します。
(public member function) [編集]
特定のサブマッチの最初の文字の位置を返します。
(public member function) [編集]
特定のサブマッチの文字シーケンスを返します。
(public member function) [編集]
指定されたサブマッチを返します。
(public member function) [編集]
ターゲットシーケンスの開始と完全なマッチの開始の間のサブシーケンスを返します。
(public member function) [編集]
完全なマッチの終了とターゲットシーケンスの終了の間のサブシーケンスを返します。
(public member function) [編集]
イテレータ
サブマッチのリストの先頭を指すイテレータを返します。
(public member function) [編集]
サブマッチのリストの末尾へのイテレータを返します。
(public member function) [編集]
フォーマット
マッチ結果を出力用にフォーマットします。
(public member function) [編集]
変更
内容を交換する
(public member function) [編集]

[編集] 非メンバ関数

(C++20で削除)
2つのマッチ結果の値を辞書順に比較する
(関数テンプレート) [edit]
std::swap アルゴリズムを特殊化する
(関数テンプレート) [edit]
English 日本語 中文(简体) 中文(繁體)