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

Fix dereference operator of VectorIterator to structures #8165

Closed
wants to merge 1 commit into from

Conversation

admo
Copy link
Contributor

@admo admo commented Nov 19, 2023

It fixes issue #8093. This is an alternative #8164 and #8166. Details in commit message.

@admo
Copy link
Contributor Author

admo commented Jan 11, 2024

@dbaileychess
This is the solution that I prefer

@admo admo force-pushed the fix_issue_8093_2 branch from de262af to f26f762 Compare March 12, 2024 10:04
@admo
Copy link
Contributor Author

admo commented Apr 29, 2024

@dbaileychess I don't want to pressure you in any way. However, what do you think? Will this change ever be merged into master?

@admo admo changed the title Fix dereference operator of VectorIterator to structures - second approach Fix dereference operator of VectorIterator to structures May 29, 2024
@admo
Copy link
Contributor Author

admo commented Sep 7, 2024

@dbaileychess Change is ready to merge. Let me know if it needs any further alignments before you accept.

For Vector or Array of structures the dereference operator of an
iterator returns the pointer to the structure. However, IndirectHelper,
which is used in the implementation of this operator, is instantiated
in the way that the IndirectHelper::Read returns structure by value.

This is because, Vector and Array instantiate IndirectHelper with
const T*, but VectorIterator instantiates IndirectHelper with T. There
are three IndirectHelper template definition: first for T, second for
Offset<T> and the last one for const T*. Those have different
IndirectHelper:Read implementations and (more importantly) return type.
This is the reason of mismatch in VectorIterator::operator* between
return type declaration and what was exactly returned.

That is, for Array<T,...> where T is scalar the VectorIterator is
instantiated as VectorIterator<T, T>, dereference operator returns T
and its implementation uses IndirectHelper<T> which Read function
returns T.
When T is not scalar, then VectorIterator is instantiated as
VectorIterator<T, const T *>, dereference operator returns const T * and
its implementation uses IndirectHelper<T> which Read function returns T.

The fix is done as follows:
* implement type trait is_specialization_of_Offset and
 is_specialization_of_Offset64,
* change partial specialization of IndirectHelper with const T * that
 it is instantiated by T and enabled only if T is not scalar and not
 specialization of Offset or Offset64,
* remove type differentiation (due to scalar) from Array..

The above makes the IndirectHelper able to correctly instantiate itself
basing only on T. Thus, the instantiation in VectorIterator correctly
instantiate IndirectHelper::Read function, especially the return type.
@admo admo force-pushed the fix_issue_8093_2 branch from b8b90be to 560efb1 Compare October 12, 2024 17:53
@admo admo closed this Oct 12, 2024
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.

1 participant