private:
void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
+ void __establish_result () {
+ if (__subs_[_N_] == -1)
+ __result_ = &__position_->prefix();
+ else
+ __result_ = &(*__position_)[__subs_[_N_]];
+ }
};
template <class _BidirectionalIterator, class _CharT, class _Traits>
__init(_BidirectionalIterator __a, _BidirectionalIterator __b)
{
if (__position_ != _Position())
- {
- if (__subs_[_N_] == -1)
- __result_ = &__position_->prefix();
- else
- __result_ = &(*__position_)[__subs_[_N_]];
- }
+ __establish_result ();
else if (__subs_[_N_] == -1)
{
__suffix_.matched = true;
{
if (__x.__result_ == &__x.__suffix_)
__result_ == &__suffix_;
+ else if ( __result_ != nullptr )
+ __establish_result ();
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
{
__position_ = __x.__position_;
if (__x.__result_ == &__x.__suffix_)
- __result_ == &__suffix_;
+ __result_ = &__suffix_;
else
__result_ = __x.__result_;
__suffix_ = __x.__suffix_;
_N_ = __x._N_;
__subs_ = __x.__subs_;
+
+ if ( __result_ != nullptr && __result_ != &__suffix_ )
+ __establish_result();
}
return *this;
}
else if (_N_ + 1 < __subs_.size())
{
++_N_;
- if (__subs_[_N_] == -1)
- __result_ = &__position_->prefix();
- else
- __result_ = &(*__position_)[__subs_[_N_]];
+ __establish_result();
}
else
{
_N_ = 0;
++__position_;
if (__position_ != _Position())
- {
- if (__subs_[_N_] == -1)
- __result_ = &__position_->prefix();
- else
- __result_ = &(*__position_)[__subs_[_N_]];
- }
+ __establish_result();
else
{
if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
std::regex phone_numbers("\\d{3}-\\d{4}");
const char phone_book[] = "555-1234, 555-2345, 555-3456";
std::cregex_iterator i(std::begin(phone_book), std::end(phone_book), phone_numbers);
+ std::cregex_iterator i2 = i;
assert(i != std::cregex_iterator());
+ assert(i2!= std::cregex_iterator());
assert((*i).size() == 1);
assert((*i).position() == 0);
assert((*i).str() == "555-1234");
+ assert((*i2).size() == 1);
+ assert((*i2).position() == 0);
+ assert((*i2).str() == "555-1234");
i++;
assert(i != std::cregex_iterator());
+ assert(i2!= std::cregex_iterator());
assert((*i).size() == 1);
assert((*i).position() == 10);
assert((*i).str() == "555-2345");
+ assert((*i2).size() == 1);
+ assert((*i2).position() == 0);
+ assert((*i2).str() == "555-1234");
i++;
assert(i != std::cregex_iterator());
+ assert(i2!= std::cregex_iterator());
assert((*i).size() == 1);
assert((*i).position() == 20);
assert((*i).str() == "555-3456");
+ assert((*i2).size() == 1);
+ assert((*i2).position() == 0);
+ assert((*i2).str() == "555-1234");
i++;
assert(i == std::cregex_iterator());
+ assert(i2!= std::cregex_iterator());
+ assert((*i2).size() == 1);
+ assert((*i2).position() == 0);
+ assert((*i2).str() == "555-1234");
+ }
+ {
+ std::regex phone_numbers("\\d{3}-\\d{4}");
+ const char phone_book[] = "555-1234, 555-2345, 555-3456";
+ std::cregex_iterator i(std::begin(phone_book), std::end(phone_book), phone_numbers);
+ std::cregex_iterator i2 = i;
+ assert(i != std::cregex_iterator());
+ assert(i2!= std::cregex_iterator());
+ assert((*i).size() == 1);
+ assert((*i).position() == 0);
+ assert((*i).str() == "555-1234");
+ assert((*i2).size() == 1);
+ assert((*i2).position() == 0);
+ assert((*i2).str() == "555-1234");
+ ++i;
+ assert(i != std::cregex_iterator());
+ assert(i2!= std::cregex_iterator());
+ assert((*i).size() == 1);
+ assert((*i).position() == 10);
+ assert((*i).str() == "555-2345");
+ assert((*i2).size() == 1);
+ assert((*i2).position() == 0);
+ assert((*i2).str() == "555-1234");
+ ++i;
+ assert(i != std::cregex_iterator());
+ assert(i2!= std::cregex_iterator());
+ assert((*i).size() == 1);
+ assert((*i).position() == 20);
+ assert((*i).str() == "555-3456");
+ assert((*i2).size() == 1);
+ assert((*i2).position() == 0);
+ assert((*i2).str() == "555-1234");
+ ++i;
+ assert(i == std::cregex_iterator());
+ assert(i2!= std::cregex_iterator());
+ assert((*i2).size() == 1);
+ assert((*i2).position() == 0);
+ assert((*i2).str() == "555-1234");
}
}
const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
phone_numbers, -1);
- assert(i != std::cregex_token_iterator());
+ std::cregex_token_iterator i2 = i;
+ std::cregex_token_iterator i3;
+ assert(i != std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
assert(i->str() == "start ");
- i++;
- assert(i != std::cregex_token_iterator());
+ assert(i2->str() == "start ");
+ i3 = i++;
+ assert(i != std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
+ assert(i3 != std::cregex_token_iterator());
assert(i->str() == ", ");
- i++;
- assert(i != std::cregex_token_iterator());
+ assert(i2->str() == "start ");
+ assert(i3->str() == "start ");
+ i3 = i++;
+ assert(i != std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
+ assert(i3 != std::cregex_token_iterator());
assert(i->str() == ", ");
- i++;
- assert(i != std::cregex_token_iterator());
+ assert(i2->str() == "start ");
+ assert(i3->str() == ", ");
+ i3 = i++;
+ assert(i != std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
+ assert(i3 != std::cregex_token_iterator());
assert(i->str() == " end");
- i++;
- assert(i == std::cregex_token_iterator());
+ assert(i2->str() == "start ");
+ assert(i3->str() == ", ");
+ i3 = i++;
+ assert(i == std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
+ assert(i3 != std::cregex_token_iterator());
+ assert(i2->str() == "start ");
+ assert(i3->str() == " end");
+ }
+ {
+ std::regex phone_numbers("\\d{3}-\\d{4}");
+ const char phone_book[] = "start 555-1234, 555-2345, 555-3456 end";
+ std::cregex_token_iterator i(std::begin(phone_book), std::end(phone_book)-1,
+ phone_numbers, -1);
+ std::cregex_token_iterator i2 = i;
+ std::cregex_token_iterator i3;
+ assert(i != std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
+ assert(i->str() == "start ");
+ assert(i2->str() == "start ");
+ i3 = i;
+ ++i;
+ assert(i != std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
+ assert(i3 != std::cregex_token_iterator());
+ assert(i->str() == ", ");
+ assert(i2->str() == "start ");
+ assert(i3->str() == "start ");
+ i3 = i;
+ ++i;
+ assert(i != std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
+ assert(i3 != std::cregex_token_iterator());
+ assert(i->str() == ", ");
+ assert(i2->str() == "start ");
+ assert(i3->str() == ", ");
+ i3 = i;
+ ++i;
+ assert(i != std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
+ assert(i3 != std::cregex_token_iterator());
+ assert(i->str() == " end");
+ assert(i2->str() == "start ");
+ assert(i3->str() == ", ");
+ i3 = i;
+ ++i;
+ assert(i == std::cregex_token_iterator());
+ assert(i2 != std::cregex_token_iterator());
+ assert(i3 != std::cregex_token_iterator());
+ assert(i2->str() == "start ");
+ assert(i3->str() == " end");
}
{
std::regex phone_numbers("\\d{3}-\\d{4}");