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

member are arrays/lists/vectors of unknown types #114

Open
michaeljhkim opened this issue Jan 18, 2025 · 12 comments
Open

member are arrays/lists/vectors of unknown types #114

michaeljhkim opened this issue Jan 18, 2025 · 12 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@michaeljhkim
Copy link

michaeljhkim commented Jan 18, 2025

Hi, how do I get the data from a member that is a vector? Keep in mind I do not know what kind of values this vector has

@BlackMATov
Copy link
Owner

Hello!

The only thing you can do in this regard is to check if the type has an index operator uvalue.has_index_op(). After that, you can take values ​​by index uvalue[42].

The types for which out-of-the-box index operators are defined can be found here: https://github.com/BlackMATov/meta.hpp/blob/main/headers/meta.hpp/meta_detail/value_traits/index_traits.hpp
You can define a specialization of this feature for other array types using the example above.

But keep in mind that this library does not have such abstractions over containers as in RTTR for a variety of reasons, the main one being that it only works in special cases and has big problems in general.

P.S.

Also, you can see another traits here: https://github.com/BlackMATov/meta.hpp/tree/main/headers/meta.hpp/meta_detail/value_traits

@BlackMATov
Copy link
Owner

You can also mark your members with metadata when binding to differentiate them.

@michaeljhkim
Copy link
Author

michaeljhkim commented Jan 18, 2025

Hello!

The only thing you can do in this regard is to check if the type has an index operator uvalue.has_index_op(). After that, you can take values ​​by index uvalue[42].

The types for which out-of-the-box index operators are defined can be found here: https://github.com/BlackMATov/meta.hpp/blob/main/headers/meta.hpp/meta_detail/value_traits/index_traits.hpp You can define a specialization of this feature for other array types using the example above.

But keep in mind that this library does not have such abstractions over containers as in RTTR for a variety of reasons, the main one being that it only works in special cases and has big problems in general.

P.S.

Also, you can see another traits here: https://github.com/BlackMATov/meta.hpp/tree/main/headers/meta.hpp/meta_detail/value_traits

Will this suffice for simple iteration? For something like a for loop? How do I get .size() for that? That is really as far as I need to go, no further

@BlackMATov
Copy link
Owner

Will this suffice for simple iteration? For something like a for loop? How do I get .size() for that? That is really as far as I need to go, no further

I think I can add something like length_traits and specialize it for sequence-like containers.

@michaeljhkim
Copy link
Author

michaeljhkim commented Jan 18, 2025

I think I can add something like length_traits and specialize it for sequence-like containers.

how difficult would it be to also implement a way to get and set values of that vector? Specifically speaking, I mean how rttr can just sort of get a array like thing where every element is now a variant:

auto view = variant.create_sequential_view();
for (size_t i = 0; i < view.get_size(); ++i)
{
	rttr::variant sub_variant = view.get_value(i);
	view.set_value(i, sub_variant);
}

In meta.hpp, it would be every element being turned into uvalue. I am trying to imitate this behaviour in some way, but it appears I cannot.

@BlackMATov
Copy link
Owner

Yes, that would be great, but it might be a lot more complicated than it seems at first glance. Anyway, give me a few days, i'm going to think about it in the background.

@michaeljhkim
Copy link
Author

Thank you for considering, I will try to find alternative solutions for now

@michaeljhkim michaeljhkim reopened this Jan 18, 2025
@BlackMATov BlackMATov added the question Further information is requested label Jan 19, 2025
BlackMATov added a commit that referenced this issue Jan 23, 2025
@BlackMATov BlackMATov mentioned this issue Jan 23, 2025
Merged
@BlackMATov
Copy link
Owner

So now we have size_traits and index_traits for uvalue.
This should be enough to iterate over sequence containers.

But we still don't have a way to set values ​​by index, and I'm not sure that I'm ready to implement that, since the concept of traits should be reconsidered, perhaps towards an analog of RTTR views or something similar.

@michaeljhkim
Copy link
Author

I think I can probably hack something together, this should be just enough. Thank you very much

@BlackMATov BlackMATov added the enhancement New feature or request label Jan 24, 2025
@michaeljhkim
Copy link
Author

michaeljhkim commented Jan 26, 2025

Okay, so I think I did come up with a temporary solution, creating a method that when called will take in uvalues and modify the value at an index.

But then this gave me an idea: why not just get pointers for the elemnts of a vector/array? As in create a uvalue for a pointer for each element? And we only do it if a user activates this feature with a function of somekind.

IDK, I'm just spitballing.

@michaeljhkim michaeljhkim reopened this Jan 26, 2025
@BlackMATov
Copy link
Owner

This is an interesting idea, but not flexible enough to include in the library. We need to be able to set values ​​by index with dynamic values. Returning a pointer to an element we need to know the static type to fully work with it, this is not what is needed.

@michaeljhkim
Copy link
Author

michaeljhkim commented Jan 28, 2025

hmmm, in that case, I'll just leave it alone, since I barely know how this stuff works. The level of abstractions are completely alien to me. I'll keep this issue open just in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants