1

I'm testing the use of an interface which has the function foo. Here is my implementation of this function in my mock:

class Mock
{
public:
    void foo(Foo::const_iterator begin, Foo::const_iterator end) {
      _begin = begin;
      _end = end;

      ...
    }
    ...
    Foo::const_iterator _begin;
    Foo::const_iterator _end;
};

I then have a test which checks if foo has been called:

// test that function foo is not called
EXPECT_EQ(mock->_begin, Foo::const_iterator());

But this is giving me an assertion in Visual Studio claiming that the iterators are incompatible. I would have expected that _begin would be equal to Foo::const_iterator() if I havent called foo(). Why isn't it?

Baz
  • 12,713
  • 38
  • 145
  • 268

2 Answers2

1

Iterators are only comparable if they're pointing to the same container. A default-constructed iterator isn't pointing to a container at all, so it's not compatible with anything by definition.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
0

Perhaps VS implements their iterator compatibility checks with default constructed iterators treated in such a way that a default constructed iterator is never compatible with any other iterator, even a default constructed one.

Mark B
  • 95,107
  • 10
  • 109
  • 188