1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <regex>
11 
12 // class match_results<BidirectionalIterator, Allocator>
13 
14 // const_reference operator[](size_type n) const;
15 
16 #include <regex>
17 #include <cassert>
18 #include "test_macros.h"
19 
20 void
test(std::regex_constants::syntax_option_type syntax)21 test(std::regex_constants::syntax_option_type syntax)
22 {
23     std::match_results<const char*> m;
24     const char s[] = "abcdefghijk";
25     assert(std::regex_search(s, m, std::regex("cd((e)fg)hi|(z)", syntax)));
26 
27     assert(m.size() == 4);
28 
29     assert(m[0].first == s+2);
30     assert(m[0].second == s+9);
31     assert(m[0].matched == true);
32 
33     assert(m[1].first == s+4);
34     assert(m[1].second == s+7);
35     assert(m[1].matched == true);
36 
37     assert(m[2].first == s+4);
38     assert(m[2].second == s+5);
39     assert(m[2].matched == true);
40 
41     assert(m[3].first == s+11);
42     assert(m[3].second == s+11);
43     assert(m[3].matched == false);
44 
45     assert(m[4].first == s+11);
46     assert(m[4].second == s+11);
47     assert(m[4].matched == false);
48 }
49 
main()50 int main()
51 {
52     test(std::regex_constants::ECMAScript);
53     test(std::regex_constants::extended);
54 }
55