Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
portsip opened this issue Aug 15, 2023 · 2 comments
Open

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

portsip opened this issue Aug 15, 2023 · 2 comments

Comments

@portsip
Copy link

portsip commented Aug 15, 2023

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

Thanks

@Tessil
Copy link
Owner

Tessil commented Aug 20, 2023

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 Tessil closed this as completed Aug 20, 2023
@Tessil Tessil reopened this Aug 20, 2023
@Tessil
Copy link
Owner

Tessil commented Aug 20, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants