ordered-map icon indicating copy to clipboard operation
ordered-map copied to clipboard

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

Open portsip opened this issue 2 years ago • 2 comments

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

Thanks

portsip avatar Aug 15 '23 09:08 portsip

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 avatar Aug 20 '23 19:08 Tessil

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.

Tessil avatar Aug 20 '23 19:08 Tessil