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 // template <class BidirectionalIterator, class Allocator, class charT, class traits>
13 // bool
14 // regex_search(BidirectionalIterator first, BidirectionalIterator last,
15 // match_results<BidirectionalIterator, Allocator>& m,
16 // const basic_regex<charT, traits>& e,
17 // regex_constants::match_flag_type flags = regex_constants::match_default);
18
19 #include <regex>
20 #include <string>
21 #include <list>
22 #include <cassert>
23
main()24 int main()
25 {
26 // This regex_iterator uses regex_search(__wrap_iter<_Iter> __first, ...)
27 // Test for http://llvm.org/bugs/show_bug.cgi?id=16240 fixed in r185273.
28 {
29 std::string s("aaaa a");
30 std::regex re("\\ba");
31 std::sregex_iterator it(s.begin(), s.end(), re);
32 std::sregex_iterator end = std::sregex_iterator();
33
34 assert(it->position(0) == 0);
35 assert(it->length(0) == 1);
36
37 ++it;
38 assert(it->position(0) == 5);
39 assert(it->length(0) == 1);
40
41 ++it;
42 assert(it == end);
43 }
44
45 // This regex_iterator uses regex_search(_BidirectionalIterator __first, ...)
46 {
47 std::string s("aaaa a");
48 std::list<char> l(s.begin(), s.end());
49 std::regex re("\\ba");
50 std::regex_iterator<std::list<char>::iterator> it(l.begin(), l.end(), re);
51 std::regex_iterator<std::list<char>::iterator> end = std::regex_iterator<std::list<char>::iterator>();
52
53 assert(it->position(0) == 0);
54 assert(it->length(0) == 1);
55
56 ++it;
57 assert(it->position(0) == 5);
58 assert(it->length(0) == 1);
59
60 ++it;
61 assert(it == end);
62 }
63 }
64