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 // class regex_iterator<BidirectionalIterator, charT, traits> 13 14 // regex_iterator operator++(int); 15 16 #include <regex> 17 #include <cassert> 18 #include "test_macros.h" 19 20 int main() 21 { 22 { 23 std::regex phone_numbers("\\d{3}-\\d{4}"); 24 const char phone_book[] = "555-1234, 555-2345, 555-3456"; 25 std::cregex_iterator i(std::begin(phone_book), std::end(phone_book), phone_numbers); 26 std::cregex_iterator i2 = i; 27 assert(i != std::cregex_iterator()); 28 assert(i2!= std::cregex_iterator()); 29 assert((*i).size() == 1); 30 assert((*i).position() == 0); 31 assert((*i).str() == "555-1234"); 32 assert((*i2).size() == 1); 33 assert((*i2).position() == 0); 34 assert((*i2).str() == "555-1234"); 35 i++; 36 assert(i != std::cregex_iterator()); 37 assert(i2!= std::cregex_iterator()); 38 assert((*i).size() == 1); 39 assert((*i).position() == 10); 40 assert((*i).str() == "555-2345"); 41 assert((*i2).size() == 1); 42 assert((*i2).position() == 0); 43 assert((*i2).str() == "555-1234"); 44 i++; 45 assert(i != std::cregex_iterator()); 46 assert(i2!= std::cregex_iterator()); 47 assert((*i).size() == 1); 48 assert((*i).position() == 20); 49 assert((*i).str() == "555-3456"); 50 assert((*i2).size() == 1); 51 assert((*i2).position() == 0); 52 assert((*i2).str() == "555-1234"); 53 i++; 54 assert(i == std::cregex_iterator()); 55 assert(i2!= std::cregex_iterator()); 56 assert((*i2).size() == 1); 57 assert((*i2).position() == 0); 58 assert((*i2).str() == "555-1234"); 59 } 60 { 61 std::regex phone_numbers("\\d{3}-\\d{4}"); 62 const char phone_book[] = "555-1234, 555-2345, 555-3456"; 63 std::cregex_iterator i(std::begin(phone_book), std::end(phone_book), phone_numbers); 64 std::cregex_iterator i2 = i; 65 assert(i != std::cregex_iterator()); 66 assert(i2!= std::cregex_iterator()); 67 assert((*i).size() == 1); 68 assert((*i).position() == 0); 69 assert((*i).str() == "555-1234"); 70 assert((*i2).size() == 1); 71 assert((*i2).position() == 0); 72 assert((*i2).str() == "555-1234"); 73 ++i; 74 assert(i != std::cregex_iterator()); 75 assert(i2!= std::cregex_iterator()); 76 assert((*i).size() == 1); 77 assert((*i).position() == 10); 78 assert((*i).str() == "555-2345"); 79 assert((*i2).size() == 1); 80 assert((*i2).position() == 0); 81 assert((*i2).str() == "555-1234"); 82 ++i; 83 assert(i != std::cregex_iterator()); 84 assert(i2!= std::cregex_iterator()); 85 assert((*i).size() == 1); 86 assert((*i).position() == 20); 87 assert((*i).str() == "555-3456"); 88 assert((*i2).size() == 1); 89 assert((*i2).position() == 0); 90 assert((*i2).str() == "555-1234"); 91 ++i; 92 assert(i == std::cregex_iterator()); 93 assert(i2!= std::cregex_iterator()); 94 assert((*i2).size() == 1); 95 assert((*i2).position() == 0); 96 assert((*i2).str() == "555-1234"); 97 } 98 } 99