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

履歴 編集

function
<regex>

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

basic_regex& operator=(const basic_regex& e);                   // (1)

basic_regex& operator=(basic_regex&& e) noexcept;               // (2)

basic_regex& operator=(const charT* ptr);                       // (3)

basic_regex& operator=(initializer_list<charT> il);             // (4)

template <class ST, class SA>
basic_regex& operator=(const basic_string<charT, ST, SA>& p);   // (5)

概要

正規表現オブジェクトを代入する。

要件

  • ptr はヌルポインタではないこと。

効果

  • (1) コピー代入演算子。assign(e) と等価。
  • (2) ムーブ代入演算子。assign(move(e)) と等価。
  • (3) assign(ptr) と等価。
  • (4) assign(il.begin(), il.end()) と等価。
  • (5) assign(p) と等価。

戻り値

*this

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

int main()
{
  const char s[] = " abc ";
  std::regex re;
  std::cout << std::boolalpha;

  const std::regex re1("\\w+");
  re = re1;                                             // (1) の形式
  std::cout << std::regex_search(s, re) << std::endl;

  re = std::regex("\\d+");                              // (2) の形式
  std::cout << std::regex_search(s, re) << std::endl;

  re = "\\w+";                                          // (3) の形式
  std::cout << std::regex_search(s, re) << std::endl;

  re = { '\\', 'd', '+' };                              // (4) の形式
  std::cout << std::regex_search(s, re) << std::endl;

  const std::string p = "\\w+";
  re = p;                                               // (5) の形式
  std::cout << std::regex_search(s, re) << std::endl;
}

出力

true
false
true
false
true

バージョン

言語

  • C++11

処理系

備考

Clang バージョン 3.0 は initializer_list に対応していないため、(4) の形式は提供されていない。
また、Clang(libc++) では例外が発生した場合に *this が元の状態を保持せずに中途半端に更新されてしまう。