blob: 8de0b650ff050571d5fc1c3ac8257700393e7d9f [file] [log] [blame]
Howard Hinnantc815a4e2013-07-11 15:32:55 +00001//===----------------------------------------------------------------------===//
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>
Marshall Clowfd5ceb22016-04-26 16:24:44 +000023#include "test_macros.h"
Howard Hinnantc815a4e2013-07-11 15:32:55 +000024
25int main()
26{
27 // This regex_iterator uses regex_search(__wrap_iter<_Iter> __first, ...)
Eric Fiselier3c354912017-02-17 08:37:03 +000028 // Test for https://bugs.llvm.org/show_bug.cgi?id=16240 fixed in r185273.
Howard Hinnantc815a4e2013-07-11 15:32:55 +000029 {
Eric Fiselieraae76492014-10-27 19:29:32 +000030 std::string s("aaaa a");
31 std::regex re("\\ba");
32 std::sregex_iterator it(s.begin(), s.end(), re);
33 std::sregex_iterator end = std::sregex_iterator();
Howard Hinnantc815a4e2013-07-11 15:32:55 +000034
35 assert(it->position(0) == 0);
36 assert(it->length(0) == 1);
37
38 ++it;
39 assert(it->position(0) == 5);
40 assert(it->length(0) == 1);
41
42 ++it;
43 assert(it == end);
44 }
45
46 // This regex_iterator uses regex_search(_BidirectionalIterator __first, ...)
47 {
Eric Fiselieraae76492014-10-27 19:29:32 +000048 std::string s("aaaa a");
49 std::list<char> l(s.begin(), s.end());
50 std::regex re("\\ba");
51 std::regex_iterator<std::list<char>::iterator> it(l.begin(), l.end(), re);
52 std::regex_iterator<std::list<char>::iterator> end = std::regex_iterator<std::list<char>::iterator>();
Howard Hinnantc815a4e2013-07-11 15:32:55 +000053
54 assert(it->position(0) == 0);
55 assert(it->length(0) == 1);
56
57 ++it;
58 assert(it->position(0) == 5);
59 assert(it->length(0) == 1);
60
61 ++it;
62 assert(it == end);
63 }
64}