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