Howard Hinnant | 7670f7d | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 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 <cassert> |
| 21 | |
| 22 | int main() |
| 23 | { |
| 24 | // Iterating over /^a/ should yield one instance at the beginning |
| 25 | // of the text. |
| 26 | |
| 27 | const char *text = "aaa\naa"; |
Eric Fiselier | e4e883e | 2014-10-27 19:29:32 +0000 | [diff] [blame] | 28 | std::regex re("^a"); |
| 29 | std::cregex_iterator it(text, text+6, re); |
| 30 | std::cregex_iterator end = std::cregex_iterator(); |
Howard Hinnant | 7670f7d | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 31 | |
| 32 | assert(it->str() == "a"); |
| 33 | assert(it->position(0) == 0); |
| 34 | assert(it->length(0) == 1); |
| 35 | |
| 36 | ++it; |
| 37 | assert(it == end); |
| 38 | } |