3514 {
3515
3516
3517
3518 const bool listener_interested = listener->IsInterested();
3519
3520
3521 ::std::vector<std::string> explanations(count());
3523 typename StlContainer::const_iterator it = stl_container.begin();
3524 size_t exam_pos = 0;
3525 bool mismatch_found = false;
3526
3527
3528
3529
3530 for (; it != stl_container.end() && exam_pos != count(); ++it, ++exam_pos) {
3531 bool match;
3532 if (listener_interested) {
3533 StringMatchResultListener
s;
3534 match = matchers_[exam_pos].MatchAndExplain(*it, &
s);
3535 explanations[exam_pos] =
s.str();
3536 } else {
3537 match = matchers_[exam_pos].Matches(*it);
3538 }
3539
3540 if (!match) {
3541 mismatch_found = true;
3542 break;
3543 }
3544 }
3545
3546
3547
3548
3549
3550 size_t actual_count = exam_pos;
3551 for (; it != stl_container.end(); ++it) {
3552 ++actual_count;
3553 }
3554
3555 if (actual_count != count()) {
3556
3557
3558
3559
3560 if (listener_interested && (actual_count != 0)) {
3561 *listener << "which has " << Elements(actual_count);
3562 }
3563 return false;
3564 }
3565
3566 if (mismatch_found) {
3567
3568 if (listener_interested) {
3569 *listener << "whose element #" << exam_pos << " doesn't match";
3571 }
3572 return false;
3573 }
3574
3575
3576
3577 if (listener_interested) {
3578 bool reason_printed = false;
3579 for (size_t i = 0; i != count(); ++i) {
3580 const std::string&
s = explanations[i];
3582 if (reason_printed) {
3583 *listener << ",\nand ";
3584 }
3585 *listener <<
"whose element #" << i <<
" matches, " <<
s;
3586 reason_printed = true;
3587 }
3588 }
3589 }
3590 return true;
3591 }
View::const_reference StlContainerReference
static const_reference ConstReference(const RawContainer &container)
void PrintIfNotEmpty(const std::string &explanation, ::std::ostream *os)