Custom Associative Container integration into entt meta #1109
Replies: 2 comments 5 replies
-
I see the point. Interesting problem actually. I did it for a couple of custom containers, namely the dense map and the dense set. However, they return a pair of references that fits the requirements. In fact, static iterator begin(const meta_ctx &area, void *container, const void *as_const) {
return container ? iterator{area, std::bool_constant<key_only>{}, static_cast<Type *>(container)->begin()}
: iterator{area, std::bool_constant<key_only>{}, static_cast<const Type *>(as_const)->begin()};
} This is where you can hook into meta probably, by means of a specialization of I can't write an example on the fly because, I mean, I'd need your container or a similar one and I don't have enough time today to pack something meaningful, sorry. However, let me know if it makes sense, then I can try to help a little further during the next days. |
Beta Was this translation helpful? Give feedback.
-
Side note for the sake of completeness: the fact is that we're dealing with an associative container and meta needs a way to lookup the key and the value in the returned object. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am trying to add my custom containers similar to std::(unordered_)map to the entt meta system. This mostly works quite straight forward. The custom containers do not use std (due to certain design decisions in there) and thus store the elements not as a pair but as a struct:
struct Entry {KeyType key; ValueType value;}
The problem arises with the iterators. I can return an iterator from that but the part in https://github.com/skypjack/entt/blob/v3.13.0/src/entt/meta/meta.hpp#L1717 requires the returned type to support
->
and have members namedfirst
andsecond
. It works for std because std returns*std::pair<KeyType, ValueType>
. For me, it gets more complicated because I can in theory just return*Entry
but then the compiler does not findfirst
on that. I could now rename my variable also in the struct but that is rather annoying because it does not match the rest of the naming scheme and I would find it rather odd that the meta system requires me to name my variables in certain way. I know that the required functions have also a requirement on the naming but these are additional functions which I can implement on top of the existing functions and group them together with comments. The first and second would leak into all implementations in the class. But it would be nice if I could somehow specify the used names for functions although I guess that will be kind of hard and a separate topic.I could also return something like
std::pair<KeyType, ValueType>
from the iterator because theoperator ->
is unused and just implemented forentt::meta
. This will fail to compile because the access in the meta.hpp is with->
and thus either requires a pointer or a type which supports that operator. If I try to return something like returning a pointer to std::pair, I need to store the pair on the iterator to make sure that it is still alive, making the iterator bigger than necessary.I also tried a struct which operates kind of like a pointer by implementing
->
but either*std::pair
is returned which leads to the same lifetime issue or storing it on the iterator or having infinite recursion if the type itself is returned.I was wondering how other people did solve this issue on custom containers.
Beta Was this translation helpful? Give feedback.
All reactions