最終更新日時(UTC):
が更新

履歴 編集

function
<regex>

std::regex_iterator::operator*(C++11)

const value_type& operator*() const;

概要

イテレータを間接参照する。

要件

シーケンスの終端を示すイテレータではない事。(シーケンス終端イテレータに対して呼び出した場合は未定義動作となる)

戻り値

メンバ変数 match への const 参照を返す。(最後にregex_search を呼び出した際の値を保持している)

備考

  • value_typeregex_iterator のメンバ型で、match_results<BidirectionalIterator> である。
  • 戻り値の型は const への参照であるため、この参照を通した変更はできない。
  • メンバ変数 match はあくまでも説明用のプライベートメンバ変数であるため、注意すること。

#include <iostream>
#include <iterator>
#include <regex>
#include <string>

int main()
{
  std::regex re("\\d+");
  std::string s("abc123def456ghi");

  for (std::sregex_iterator it(std::begin(s), std::end(s), re), end; it != end; ++it) {
    auto&& match = *it;
    std::cout << "prefix = '" << match.prefix() << "', str = '" << match.str() << "', suffix = '" << match.suffix() << '\'' << std::endl;
  }
}

出力

prefix = 'abc', str = '123', suffix = 'def456ghi'
prefix = 'def', str = '456', suffix = 'ghi'

バージョン

言語

  • C++11

処理系

関連項目

名前 説明 対応バージョン
operator-> メンバアクセス C++11
(constructor) コンストラクタ C++11
operator++ インクリメント C++11
operator== 等値比較 C++11