sub_match::difference_type
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

sub_match::difference_type

The type of an iterator difference.

typedef typename iterator_traits<BidIt>::difference_type difference_type;

The typedef is a synonym for iterator_traits<BidIt>::difference_type.

 

// std_tr1__regex__sub_match_difference_type.cpp 
// compile with: /EHsc 
#include <regex> 
#include <iostream> 
 
int main() 
    { 
    std::tr1::regex rx("c(a*)|(b)"); 
    std::tr1::cmatch mr; 
 
    std::tr1::regex_search("xcaaay", mr, rx); 
 
    std::tr1::csub_match sub = mr[1]; 
    std::cout << "matched == " << std::boolalpha 
        << sub.matched << std::endl; 
    std::cout << "length == " << sub.length() << std::endl; 
 
    std::tr1::csub_match::difference_type dif = std::distance(sub.first, sub.second); 
    std::cout << "difference == " << dif << std::endl; 
 
    std::tr1::csub_match::iterator first = sub.first; 
    std::tr1::csub_match::iterator last = sub.second; 
    std::cout << "range == " << std::string(first, last) 
        << std::endl; 
    std::cout << "string == " << sub << std::endl; 
 
    std::tr1::csub_match::value_type *ptr = "aab"; 
    std::cout << "compare(\"aab\") == " 
        << sub.compare(ptr) << std::endl; 
    std::cout << "compare(string) == " 
        << sub.compare(std::string("AAA")) << std::endl; 
    std::cout << "compare(sub) == " 
        << sub.compare(sub) << std::endl; 
 
    return (0); 
    } 
 
matched == true length == 3 difference == 3 range == aaa string == aaa compare("aab") == -1 compare(string) == 1 compare(sub) == 0

Header: <regex>

Namespace: std::tr1

Show:
© 2016 Microsoft