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

履歴 編集

<regex>

std::basic_regex::推論補助(C++17)

namespace std {
  template <class ForwardIterator>
  basic_regex(ForwardIterator, ForwardIterator,
    regex_constants::syntax_option_type = regex_constants::ECMAScript)
    -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>;
}

概要

std::basic_regexクラステンプレートの型推論補助。イテレータ範囲から文字型を推論する。

#include <regex>
#include <type_traits>

int main()
{
  std::string re_str = R"(^\d+$)";

  // 文字列から推論
  std::basic_regex re1(re_str);
  static_assert(std::is_same_v<decltype(re1), std::regex>);

  std::basic_regex re2(re_str, std::regex_constants::ECMAScript);
  static_assert(std::is_same_v<decltype(re2), std::regex>);

  // イテレータ範囲から推論
  std::basic_regex re3(re_str.begin(), re_str.end());
  static_assert(std::is_same_v<decltype(re3), std::regex>);
}

出力

バージョン

言語

  • C++17

処理系

関連項目

参照