flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

Get non-const object from VectorIterator (C++, flatbuffers 1.8.0)

Open stan1199 opened this issue 3 years ago • 2 comments

I was wondering if there is a way to retrieve a non-const reference to an object from a VectorIterator object that is pointing to it. Looking at the code, doesn't seem like there is a way to get the non-const reference to an object.

template struct IndirectHelper { typedef T return_type; typedef T mutable_return_type; static const size_t element_stride = sizeof(T); static return_type Read(const uint8_t *p, uoffset_t i) { return EndianScalar((reinterpret_cast<const T *>(p))[i]); } }; template<typename T, typename IT> struct VectorIterator { ... IT operator *() const { return IndirectHelper::Read(data_, 0); } ... }

Even though mutable_return_type is declared in the IndirectHelper method, it is not used and in the end, we get the const object only upon indirection of the VectorIterator object. I couldn't find any other method in VectorIterator that can get me the non-const object. Am I missing something?

stan1199 avatar Jun 06 '23 09:06 stan1199

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

github-actions[bot] avatar Dec 05 '23 20:12 github-actions[bot]

This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.

github-actions[bot] avatar Dec 20 '23 20:12 github-actions[bot]