alecthomas / entityx

EntityX - A fast, type-safe C++ Entity-Component system
MIT License
2.23k stars 295 forks source link

Add dereference operator to ComponentHandle #169

Closed lethal-guitar closed 7 years ago

lethal-guitar commented 7 years ago

This makes it possible to write code like this:

auto& componentRef = *someEntity.component<Position>();
componentRef.x += 2;

This was already possible previously, but required calling .get() on the component handle in addition to dereferencing. Having this operator also makes the component handle more consistent with common smart pointer types, since it already has the -> operator.

I wasn't sure whether it makes sense to add a test for something so trivial, but I did for now.