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 // UNSUPPORTED: c++98, c++03
11 
12 // <regex>
13 
14 // class regex_token_iterator<BidirectionalIterator, charT, traits>
15 
16 // regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
17 //                      const regex_type& re,
18 //                      initializer_list<int> submatches,
19 //                      regex_constants::match_flag_type m =
20 //                                              regex_constants::match_default);
21 
22 #include <regex>
23 #include <cassert>
24 #include "test_macros.h"
25 
main()26 int main()
27 {
28     {
29         std::regex phone_numbers("\\d{3}-(\\d{4})");
30         const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
31         std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
32                                      phone_numbers, {-1, 0, 1});
33         assert(i != std::cregex_token_iterator());
34         assert(i->str() == "start ");
35         ++i;
36         assert(i != std::cregex_token_iterator());
37         assert(i->str() == "555-1234");
38         ++i;
39         assert(i != std::cregex_token_iterator());
40         assert(i->str() == "1234");
41         ++i;
42         assert(i != std::cregex_token_iterator());
43         assert(i->str() == ", ");
44         ++i;
45         assert(i != std::cregex_token_iterator());
46         assert(i->str() == "555-2345");
47         ++i;
48         assert(i != std::cregex_token_iterator());
49         assert(i->str() == "2345");
50         ++i;
51         assert(i != std::cregex_token_iterator());
52         assert(i->str() == ", ");
53         ++i;
54         assert(i != std::cregex_token_iterator());
55         assert(i->str() == "555-3456");
56         ++i;
57         assert(i != std::cregex_token_iterator());
58         assert(i->str() == "3456");
59         ++i;
60         assert(i != std::cregex_token_iterator());
61         assert(i->str() == " end");
62         ++i;
63         assert(i == std::cregex_token_iterator());
64     }
65 }
66