Entt: Proposal for registry::any<>

Created on 12 Dec 2019  路  5Comments  路  Source: skypjack/entt

As mentioned in chat, there might be an opportunity for the API to save a few characters from being typed, by introducing a any to the registry.

Before

if (_registry.has<Selected>(entity) ||
    _registry.has<SelectedByParent>(entity) ||
    _registry.has<SelectedByChild>(entity))
{
  flags |= ImGuiTreeNodeFlags_Selected;
}

After

if (_registry.any<Selected, SelectedByParent, SelectedByChild>(entity) {
  flags |= ImGuiTreeNodeFlags_Selected;
}
feature request

Most helpful comment

What about the following instead?

registry.has<A, B>(entity, entt::any<C, D>);

That is: entity has both A and B and any of C and D.
This could make possible more complex queries like the one above.
Your case becomes:

registry.has<>(entity, entt::any<Selected, SelectedByParent, SelectedByChild>);

All 5 comments

What about the following instead?

registry.has<A, B>(entity, entt::any<C, D>);

That is: entity has both A and B and any of C and D.
This could make possible more complex queries like the one above.
Your case becomes:

registry.has<>(entity, entt::any<Selected, SelectedByParent, SelectedByChild>);

That could work, but I'm not a fan of how it reads.

  1. registry, has.. what?
  2. In this entity
  3. Any of <these>
  4. Do something

Now .has<> is noise, and the other entt:: is more noise. You would have to have read it a few times to understand its meaning. As opposed to..

  1. registry, any of these
  2. Do something

Which isn't as clear as registry.has<> which is almost English, but closer. My picks would be, in this order:

  1. registry.any<A, B>(entity)
  2. registry.has<A, B>(entity, entt::any)

Just to be sure, are you suggesting to implement both of them or just the first one from your list?

That's up to you, I meant either one or the other, with more preference to the first.

I added registry::any, it was actually easier to read and to work with.
I'll push it upstream soon, most likely tomorrow since I'm out of home today. :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skypjack picture skypjack  路  6Comments

markand picture markand  路  5Comments

blockspacer picture blockspacer  路  3Comments

skypjack picture skypjack  路  4Comments

Kerndog73 picture Kerndog73  路  5Comments