Add support for type checked term_at<T> and term_at<T>(i) #1397
+149
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First method is simple loop over terms to find term for T. Its slower than using index directly, but sometimes type safety is more preferred and when the cost is only on initialization.
Second method is same as term_at(i) but with type checked assert. For middle ground to still keep the safety but also performance.
This is mostly to mirror the C# binding PR where this is slightly more useful but maybe cpp would benefit too:
BeanCheeseBurrito/Flecs.NET#52
Also disclaimer, I dont rly work with cpp often so I might've easily missed something, but I made best effort to write some tests and at least run them and see if they pass :d
Example use:
Current method
world.System<Position, Velocity>() .term_at(1) .singleton();
Type checked (throws assert if term_at(1) isnt Velocity type)
world.System<Position, Velocity>() .term_at<Velocity>(1) .singleton();
Type checked + resolved (throws assert if there is no Velocity component):