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

履歴 編集

function
<regex>

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

regex_iterator& operator=(const regex_iterator& rhs);

概要

rhs*this にコピーする。

効果

rhs の状態を *this にコピーする。

戻り値

*this

備考

規格書には特に記載は無いが、前方向イテレータの要件から、コピー元オブジェクトの全ての状態を引き継ぐと考えてよいものと思われる。

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

int main()
{
  std::regex re("\\d+");
  std::string s("+++111---222+++333---");

  std::sregex_iterator it1;
  for (std::sregex_iterator it2(std::begin(s), std::end(s), re), end; it2 != end; ++it2) {
    if (it2->str() == "222") {
      it1 = it2;
    }
    std::cout << "position = " << it2->position() << ", length = " << it2->length() << ", str = '" << it2->str() << "', prefix = '" << it2->prefix() << "', suffix = '" << it2->suffix() << '\'' << std::endl;
  }
  std::cout << std::endl;

  for (std::sregex_iterator end; it1 != end; ++it1) {
    std::cout << "position = " << it1->position() << ", length = " << it1->length() << ", str = '" << it1->str() << "', prefix = '" << it1->prefix() << "', suffix = '" << it1->suffix() << '\'' << std::endl;
  }
}

出力

position = 3, length = 3, str = '111', prefix = '+++', suffix = '---222+++333---'
position = 9, length = 3, str = '222', prefix = '---', suffix = '+++333---'
position = 15, length = 3, str = '333', prefix = '+++', suffix = '---'

position = 9, length = 3, str = '222', prefix = '---', suffix = '+++333---'
position = 15, length = 3, str = '333', prefix = '+++', suffix = '---'

バージョン

言語

  • C++11

処理系

備考

GCC & libstdc++ では、コピー後のオブジェクトの match.position(i) が補正されずに誤っている。(補正については operator++ の「効果」を参照)

関連項目

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