alecthomas / entityx

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

Allow for move-only components. #208

Open tylerreisinger opened 6 years ago

tylerreisinger commented 6 years ago

Right now, trying to do e.assign<C>(...) for some C that has a deleted copy constructor will cause a substitution error when instantiating ComponentHelper::copy_component_to, even if that method is never called as the vtable still must be constructed. It would be nice to have proper support for move-only components as well.

A simple solution is to use SFINAE on ComponentHelper:

template <typename C>
+class ComponentHelper<C, std::enable_if_t<!std::is_copy_constructible_v<C>>>: public BaseComponentHelper { ... }

and to not actually copy in copy_component_to, but that delays any errors trying to copy until runtime. That is suboptimal, and there should be a much more elegant solution.

lethal-guitar commented 6 years ago

This would be nice. I can't verify at the moment, but I believe this used to work in an earlier version, the 1.2.0 release. Might be interesting to double check that it used to work, and then find the commit that changed it, maybe this gives some insight into how to bring it back while keeping improvements done in the meantime.