- regex[meta header]
- std[meta namespace]
- class template[meta id-type]
- cpp11[meta cpp]
namespace std {
template <class CharT>
struct regex_traits;
}
regex_traits
は、正規表現ライブラリ<regex>
クラス内で使用される、文字とその変換の規則に関する特性を表すクラスである。
標準ライブラリは std::regex_traits<char>
と std::regex_traits<wchar_t>
に対し有効な特殊化を定義する。それ以外の型については、このクラスと同じインタフェースのクラスを実装することで、特定の文字コードの場合に、正規表現の振る舞いをカスタマイズできる。
名前 |
説明 |
対応バージョン |
(constructor) |
コンストラクタ |
C++11 |
~regex_traits() = default; |
デストラクタ |
C++11 |
regex_traits& operator=(const regex_traits&) = default; regex_traits& operator=(regex_traits&&) = default; |
代入演算子 |
C++11 |
名前 |
説明 |
対応バージョン |
length |
文字列の長さを取得する |
C++11 |
名前 |
説明 |
対応バージョン |
char_type |
テンプレートパラメータCharT |
C++11 |
string_type |
char_type 文字を要素とする文字列型 std::basic_string <char_type> |
C++11 |
locale_type |
ロケール型 std::locale |
C++11 |
char_class_type |
正規表現の文字クラス名を表す、実装定義のビットマスク型 |
C++11 |
#include <iostream>
#include <regex>
#include <string>
int main()
{
std::regex_traits<char> traits;
std::string class_name = "alnum"; // 正規表現中で[[:alnum:]]のように入力するクラス名
// 文字'a'がアルファベットと数字のクラスに含まれているかを判定する
if (traits.isctype('a', traits.lookup_classname(class_name.begin(), class_name.end()))) {
std::cout << "'a' is alpha-numeric class" << std::endl;
}
else {
std::cout << "'a' is not alpha-numeric class" << std::endl;
}
}
- std::regex_traits[color ff0000]
- class_name.begin()[link /reference/string/basic_string/begin.md]
- class_name.end()[link /reference/string/basic_string/end.md]
- traits.isctype[link regex_traits/isctype.md]
- traits.lookup_classname[link regex_traits/lookup_classname.md]
'a' is alpha-numeric class
- Clang: 3.0 [mark verified], 3.1 [mark verified], 3.2 [mark verified], 3.3 [mark verified], 3.4 [mark verified], 3.5 [mark verified], 3.6 [mark verified]
- GCC: 4.9.0 [mark verified], 4.9.1 [mark verified], 4.9.2 [mark verified], 5.0.0 [mark verified]
- ICC: ??
- Visual C++: ??