1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <regex>
10
11// class regex_token_iterator<BidirectionalIterator, charT, traits>
12
13// template <size_t N>
14// regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
15// const regex_type& re,
16// const int (&submatches)[N],
17// regex_constants::match_flag_type m =
18// regex_constants::match_default);
19
20#include <regex>
21#include <cassert>
22#include <iterator>
23
24#include "test_macros.h"
25
26int main(int, char**)
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 const int indices[] = {-1, 0, 1};
32 std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
33 phone_numbers, indices);
34 assert(i != std::cregex_token_iterator());
35 assert(i->str() == "start ");
36 ++i;
37 assert(i != std::cregex_token_iterator());
38 assert(i->str() == "555-1234");
39 ++i;
40 assert(i != std::cregex_token_iterator());
41 assert(i->str() == "1234");
42 ++i;
43 assert(i != std::cregex_token_iterator());
44 assert(i->str() == ", ");
45 ++i;
46 assert(i != std::cregex_token_iterator());
47 assert(i->str() == "555-2345");
48 ++i;
49 assert(i != std::cregex_token_iterator());
50 assert(i->str() == "2345");
51 ++i;
52 assert(i != std::cregex_token_iterator());
53 assert(i->str() == ", ");
54 ++i;
55 assert(i != std::cregex_token_iterator());
56 assert(i->str() == "555-3456");
57 ++i;
58 assert(i != std::cregex_token_iterator());
59 assert(i->str() == "3456");
60 ++i;
61 assert(i != std::cregex_token_iterator());
62 assert(i->str() == " end");
63 ++i;
64 assert(i == std::cregex_token_iterator());
65 }
66
67 return 0;
68}
69

source code of libcxx/test/std/re/re.iter/re.tokiter/re.tokiter.cnstr/array.pass.cpp