最終更新日時:
が更新

履歴 編集

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_type は locale である。

例

#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

処理系

  • Clang: 3.0 ✅, 3.1 ✅, 3.2 ✅, 3.3 ✅, 3.4 ✅, 3.5 ✅, 3.6 ✅
  • GCC: 4.9.0 ✅, 4.9.1 ✅, 4.9.2 ✅, 5.0.0 ✅
  • Visual C++: ??

備考

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