mattreecebentley / plf_hive

plf::hive is a fork of plf::colony to match the current C++ standards proposal.
https://plflib.org/colony.htm
zlib License
71 stars 7 forks source link

Wrong output of `advance(it, -1)` #25

Closed Quuxplusone closed 2 years ago

Quuxplusone commented 2 years ago
int main() {
    plf::hive<int> h = {1,0,1};
    std::erase(h, 0);
    auto it = h.end();
    auto jt = h.end();
    std::advance(it, -1);  // use the operator-=()-alike `advance` overload
    --jt;                  // use operator--()
    assert(it == jt);      // assert-fails
}

The bug here seems to be not just the mirror-image of #24, but actually down at https://github.com/mattreecebentley/plf_hive/blob/main/plf_hive.h#L730 instead (it should use last_endpoint instead of capacity).

mattreecebentley commented 2 years ago

Fixed, thanks-