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

履歴 編集

function
<regex>

std::basic_regex::imbue(C++11)

locale_type imbue(locale_type loc);

概要

ロケールを設定する。

効果

*this に保持されている traits_type 型のオブジェクト traits_inst に対して、traits_inst.imbue(loc) を呼び出し、その結果を返す。
本設定後、*this はいかなる文字列にもマッチしない。(つまり、デフォルト初期化された状態と同様)

戻り値

現在設定されているロケール

備考

  • traits_instデフォルト初期化されたオブジェクトである。
  • 効果に記載されている通り、本メンバ関数呼び出し後、*this はいかなる文字列にもマッチしない。
    従って、*this を使用するためには、operator=assign を用いて正規表現を代入しなければならない。
  • locale_type は、ロケールに関する型であり、traits_type::locale_type の別名である。
  • traits_type は、クラステンプレート basic_regex の 2 番目のテンプレート引数で、デフォルトでは regex_traits<char_type> である。
    その場合、locale_typelocale である。

#include <iostream>
#include <locale>
#include <regex>

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

  std::cout << std::regex_search(s, re) << std::endl;

  auto loc = re.imbue(std::locale::classic());
  std::cout << std::regex_search(s, re) << std::endl;

  re = "\\w+";
  std::cout << std::regex_search(s, re) << std::endl;
}

出力

true
false
true

バージョン

言語

  • C++11

処理系

備考

GCC(libstdc++) では、本メンバ関数を呼び出しても *this は元の正規表現を保持したままとなってしまっている。