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

add support for structed bindings for Ogre::Vector #3217

Closed
wants to merge 4 commits into from

Conversation

ribbon-otter
Copy link
Contributor

It would be nice to be able to write

auto [x,y,z] = myVector;

to conveniently pull myVector apart into its components for some algorithms. This pull request makes turns Ogre::Vector into a tuple-like (as defined in the C++ std library), so that structured binding is supported. Given that Ogre::Vector is a fixed length container, it is in many ways an specialized alternative to std::array, and std::array is also a tuple-like.

I invite feedback, particularly since Ogre::Vector is such a fundamental part of the Ogre project, and I am venturing into unfamiliar parts of the C++ language with this pull request.

@ribbon-otter
Copy link
Contributor Author

looks like I forgot (and didn't find) how to run the tests that include trailing whitespace locally.

@paroj
Copy link
Member

paroj commented Sep 8, 2024

auto& [x,y,z] = myVector;
x = 1;

this should modify myVector.x, but currently will not work, right?

@paroj
Copy link
Member

paroj commented Sep 9, 2024

I did some tests:

for types that go through the VectorBase specialization things just work without this PR:

    Vector3 v;
    auto& [a,b,c] = v;
    a = 1;

the only problem are types that use the generic path:

    Vector3i v;
    auto& [a,b,c] = v.data;
    a = 1;

they need .data added

@paroj
Copy link
Member

paroj commented Sep 22, 2024

closing for now

@paroj paroj closed this Sep 22, 2024
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

Successfully merging this pull request may close these issues.

2 participants