- regex[meta header]
- std[meta namespace]
- match_results[meta class]
- function[meta id-type]
- cpp11[meta cpp]
match_results(const Allocator& a = Allocator()); // (1)
match_results() : match_results(Allocator()) {} // (1) C++20
match_results(const Allocator& a); // (2) C++20
match_results(const match_results& m); // (3)
match_results(match_results&& m) noexcept; // (4)
match_results
オブジェクトを構築する。
- (4)
Allocator
のムーブコンストラクタは例外で終了しないこと。
- (1) デフォルトコンストラクタ。
- C++17まで : 指定したアロケータ
a
を用いてmatch_results
オブジェクトを構築する。 - C++20 : アロケータをデフォルト構築して
match_results
オブジェクトを構築する。
- C++17まで : 指定したアロケータ
- (2) 指定したアロケータ
a
を用いてmatch_results
オブジェクトを構築する。 - (3) コピーコンストラクタ。引数
m
をコピーしたmatch_results
オブジェクトを構築する。 - (4) ムーブコンストラクタ。引数
m
をムーブしたmatch_results
オブジェクトを構築する。
-
(1)(2)
ready
() == false
、かつ、size
() == 0
、かつ、get_allocator
() == a
-
(3) 構築したオブジェクトを
u
とすると、u == m
-
(4) 以下の表を満たす。
要素 値 ready
()
m.
ready
()
size
()
m.
size
()
str
(n)
n <
size
()
である全ての整数n
について、m.
str
(n)
prefix
()
m.
prefix
()
suffix
()
m.
suffix
()
(*this)[n]
n <
size
()
である全ての整数n
について、m[n]
length
()
n <
size
()
である全ての整数n
について、m.
length
(n)
position
()
n <
size
()
である全ての整数n
について、m.
position
(n)
get_allocator
()
m.
get_allocator
(n)
- (1)(2) 定数時間
- (3) 線形時間
- (4) 定数時間
規格では明確ではないものの、(3) の形式でも以下の事後条件を満たすべきであると思われる。
- (4) の事後条件のアロケータ以外のもの
get_allocator
() ==
allocator_traits
<allocator_type>::
select_on_container_copy_construction
(m.
get_allocator
())
#include <iostream>
#include <regex>
void print(const std::cmatch& m)
{
std::cout << "ready:" << std::boolalpha << m.ready() << std::endl;
if (m.ready()) {
std::cout << "prefix:'" << m.prefix() << '\'' << std::endl;
for (std::size_t i = 0, n = m.size(); i < n; ++i) {
std::cout << i << ":'" << m.str(i) << '\'' << std::endl;
}
std::cout << "suffix:'" << m.suffix() << '\'' << std::endl;
}
std::cout << std::endl;
}
int main()
{
const char s[] = " abc 123 def ";
const std::regex re("(\\w+) (\\d+) (\\w+)");
std::cmatch m1; // (1) の形式
print(m1);
std::regex_search(s, m1, re);
print(m1);
std::cmatch m2(m1); // (3) の形式
print(m2);
std::cmatch m3(std::move(m1)); // (4) の形式
print(m3);
}
- m.size()[link size.md]
- std::regex[link ../basic_regex.md]
- m.prefix()[link prefix.md]
- m.suffix()[link suffix.md]
- m.str[link str.md]
- m.ready()[link ready.md]
- std::cmatch[link ../match_results.md]
- std::regex_search[link ../regex_search.md]
- std::move[link ../../utility/move.md]
ready:false
ready:true
prefix:' '
0:'abc 123 def'
1:'abc'
2:'123'
3:'def'
suffix:' '
ready:true
prefix:' '
0:'abc 123 def'
1:'abc'
2:'123'
3:'def'
suffix:' '
ready:true
prefix:' '
0:'abc 123 def'
1:'abc'
2:'123'
3:'def'
suffix:' '
- C++11
- 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], 5.0.0 [mark verified]
- ICC: ??
- Visual C++: ??
GCC(libstdc++) の 4.9.2 までは、regex_iterator
を間接参照した結果から (2)、あるいは、(3) の形式で構築した場合に position
の結果が正しくコピーされない。これは、4.9.3 以降で修正される予定である。