Tessil / ordered-map

C++ hash map and hash set which preserve the order of insertion
MIT License
512 stars 66 forks source link

Issues with the operators of the iterator #3

Closed HenryRLee closed 7 years ago

HenryRLee commented 7 years ago

Hi, I just found two issues related to the operators + of the iterator.

The first one is, the n + iterator operator is missing, which is required in a random-access iterator. More specifically, this operator override is missing: ordered_iterator operator+(difference_type, const ordered_iterator&). As a consequence, this piece of code couldn't be compiled:

    tsl::ordered_map<int, int> mymap = {{-1, 15}, {-2, 17}};
    tsl::ordered_map<int, int>::iterator it = mymap.begin();

    BOOST_CHECK_EQUAL(it->second, 15);

    it = 1 + it;
    BOOST_CHECK_EQUAL(it->second, 17);

The second issue is that, the iterator + iterator operator shouldn't exist. As no standard iterator overrides this operator. So this code also doesn't work:

    tsl::ordered_map<int, int> mymap = {{-1, 15}, {-2, 17}};
    tsl::ordered_map<int, int>::iterator it = mymap.begin();

    it + it;
Tessil commented 7 years ago

Thank you. I effectively mixed up the ordered_iterator operator+(difference_type, const ordered_iterator&) and difference_type operator+(const ordered_iterator& lhs, const ordered_iterator& rhs).

HenryRLee commented 7 years ago

My pleasure