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

[vector] Allow to iterate with mutables #7586

Merged
merged 3 commits into from
Oct 21, 2022

Conversation

ArnaudD-FR
Copy link
Contributor

When using mutable buffers it is currently impossible to deference iterators without having a compiler error due to struct IndirectHelper::Read returning return_type instead of mutable_return_type:

struct VectorIterator {
...
// compiler error: failed to convert const value (IndirectHelper::return_type)
// to non const value (IndirectHelper::mutable_return_type, aka IT)
IT operator*() const { return IndirectHelper::Read(data_, 0); }
IT operator->() const { return IndirectHelper::Read(data_, 0); }
...
};

The main idea behind this PR is to have an VectorIterator using uint8_t * and VectorConstIterator using const uint8_t * as data to use the correct overload of IndirectHelper::Read

So VectorIterator has a new template parameter to switch from const_iterator to iterator. Side effect, as array was also using VectorIterator it is now using VectorConstIterator.

This will fix issue #4674

Duplicate of PR #7294

@github-actions github-actions bot added the c++ label Oct 14, 2022
@dbaileychess dbaileychess merged commit 5b3fadc into google:master Oct 21, 2022
@dbaileychess
Copy link
Collaborator

Thanks! Sorry for the delay.

bulentv pushed a commit to zdrealityhub/flatbuffers that referenced this pull request Oct 21, 2022
Co-authored-by: ArnaudD-FR <arnaud.desmier@gmail.com>
Co-authored-by: Derek Bailey <derekbailey@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants