Export (0) Print
Expand All

regex_token_iterator::operator++

Increments the iterator.

regex_token_iterator& operator++();
regex_token_iterator& operator++(int);

If the stored iterator it is an end-of-sequence iterator the first operator sets the stored value pos to the value of subs.size() (thus making an end-of-sequence iterator). Otherwise the operator increments the stored value pos; if the result is equal to the value subs.size() it sets the stored value pos to zero and increments the stored iterator it. If incrementing the stored iterator leaves it unequal to an end-of-sequence iterator the operator does nothing further. Otherwise, if the end of the preceding match was at the end of the character sequence the operator sets the stored value of pos to subs.size(). Otherwise, the operator repeatedly increments the stored value pos until pos == subs.size() or subs[pos] == -1 (thus ensuring that the next dereference of the iterator will return the tail of the character sequence if one of the index values is -1). In all cases the operator returns the object.

The second operator makes a copy of the object, increments the object, then returns the copy.

 

// std_tr1__regex__regex_token_iterator_operator_inc.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 
 
typedef std::regex_token_iterator<const char *> Myiter; 
int main() 
    { 
    const char *pat = "aaxaayaaz"; 
    Myiter::regex_type rx("(a)a"); 
    Myiter next(pat, pat + strlen(pat), rx); 
    Myiter end; 
 
// show whole match 
    for (; next != end; ++next) 
        std::cout << "match == " << next->str() << std::endl; 
    std::cout << std::endl; 
 
// show prefix before match 
    next = Myiter(pat, pat + strlen(pat), rx, -1); 
    for (; next != end; ++next) 
        std::cout << "match == " << next->str() << std::endl; 
    std::cout << std::endl; 
 
// show (a) submatch only 
    next = Myiter(pat, pat + strlen(pat), rx, 1); 
    for (; next != end; ++next) 
        std::cout << "match == " << next->str() << std::endl; 
    std::cout << std::endl; 
 
// show prefixes and submatches 
    std::vector<int> vec; 
    vec.push_back(-1); 
    vec.push_back(1); 
    next = Myiter(pat, pat + strlen(pat), rx, vec); 
    for (; next != end; ++next) 
        std::cout << "match == " << next->str() << std::endl; 
    std::cout << std::endl; 
 
// show prefixes and whole matches 
    int arr[] = {-1, 0}; 
    next = Myiter(pat, pat + strlen(pat), rx, arr); 
    for (; next != end; ++next) 
        std::cout << "match == " << next->str() << std::endl; 
    std::cout << std::endl; 
 
// other members 
    Myiter it1(pat, pat + strlen(pat), rx); 
    Myiter it2(it1); 
    next = it1; 
 
    Myiter::iterator_category cat = std::forward_iterator_tag(); 
    Myiter::difference_type dif = -3; 
    Myiter::value_type mr = *it1; 
    Myiter::reference ref = mr; 
    Myiter::pointer ptr = &ref; 
 
    dif = dif; // to quiet "unused" warnings 
    ptr = ptr; 
 
    return (0); 
    } 
 
match == aa
match == aa
match == aa

match == 
match == x
match == y
match == z

match == a
match == a
match == a

match == 
match == a
match == x
match == a
match == y
match == a
match == z

match == 
match == aa
match == x
match == aa
match == y
match == aa
match == z

Header: <regex>

Namespace: std

Show:
© 2014 Microsoft