flatbuffers
flatbuffers copied to clipboard
[vector] Allow to iterate with mutables
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<T>::return_type)
// to non const value (IndirectHelper<T>::mutable_return_type, aka IT)
IT operator*() const { return IndirectHelper<T>::Read(data_, 0); }
IT operator->() const { return IndirectHelper<T>::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<T>::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
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
For more information, open the CLA check for this pull request.
@ArnaudD-FR Do you plan on addressing the comments?
@dbaileychess Do you have a place to put the sample test code?
@dbaileychess Do you have a place to put the sample test code?
@ArnaudD-FR I would just add something to tests/test.cpp
.
@dbaileychess Why was this closed? Lack of tests? I spent the last few hours trying to debug obscure template errors caused by this and been ripping my hair out, would love to see this fixed.
Is there any known workaround?
@dbaileychess , sorry for delay, many changes on my professional life those last months. Can you reopen this issue? I provided the test. Just tell me if this is what you expect.
Just open a new PR. I close PRs that don't get any activity.