Tessil / ordered-map

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

It's possible provide the value() method for reverse_iterator? #43

Open portsip opened 1 year ago

portsip commented 1 year ago

It's possible provide the value() method for reverse_iterator?

Thanks

Tessil commented 1 year ago

The following should work:


int main() {
  tsl::ordered_map<int, int> map = {{0, 2}, {1, 3}};

  for (auto it = map.rbegin(); it != map.rend(); ++it) {
    it.base().value() = 1;
  }
}
Tessil commented 1 year ago

I just realised in the base() documentation that The base iterator refers to the element that is next (from the std::reverse_iterator::iterator_type perspective) to the element the reverse_iterator is currently pointing to.

The above will thus not work as expected, I need to check if there's a better solution.

Something like:

(it.base() - 1).value() = 1;

would work but is very cumbersome and unintuitive.