I put together this test case that reproduces the conditions and problem I'm getting in larger code. I do in fact need to copy from a C array of POD structures, but I'd like the destination to be a vector so it can handle the copy deletion on its own.

    struct W { long a; int b; char c; char d; };
    W block[1] = { { 15, 42, 'D', 'X' } };
    std::vector<W> dest;
    std::copy(block, block+1, dest.begin());
    Assert::AreEqual(42, dest[0].b);

The assertion "cannot seek vector iterator after end" seems to be occurring within the dest.begin() call, which makes no sense to me. I'm sure I'm just missing an obvious detail, but what is it?

0 Answers