-
-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow aggregate initialisation of components? #212
Comments
Yes this has been considered before, but I believe it would break API compatibility. |
See #87. |
I wonder if it's possible to achieve backwards compatibility with SFINAE... |
Hmmm I suspect trying to SFINAE to the correct types would be a direct clash with the use of variadic arguments, but that's just my initial feel. In general though the narrowing conversion issues are pretty easy to get around. They only really occur when using literals or ambiguous temporaries. This can be resolved by ensuring the right types are passed in e.g. int(5) rather than just 5 or std::string("oeau") instead of "oeau". Still would be a major compatibility issue for existing code bases. For me though I've made the change locally as removing the need to write endless redundant constructors comes with almost no cost. I think the change is a good one in general for any new project using EntityX. |
@alecthomas , @radman0x We may implement the selection of construction type using the code like that: template< typename TComponent, typename... TArguments >
inline typename std::enable_if<IS_AGGREGATE<TComponent>, TComponent*>::type Construct(void* component_memory, TArguments&&... arguments)
{
// Brace-initialization / aggregate construction.
return new( component_memory ) TComponent{ std::forward<TArguments>( arguments )... };
}
template< typename TComponent, typename... TArguments >
inline typename std::enable_if<!IS_AGGREGATE<TComponent>, TComponent*>::type Construct(void* component_memory, TArguments&&... arguments)
{
// Narrowing construction.
return new( component_memory ) TComponent( std::forward<TArguments>( arguments )... );
} The question is inside of Currently, using the C++17 standard, we can operate with For earlier C++ standards we can use the Here is the link to test code, which uses the BTW, @alecthomas , what C++ standard is current for EntityX? Is it still C++11? |
Thanks @FrankStain . You know what, let me tag a stable version, then if you feel like sending a PR with your proposed change @radman0x, I'll merge it. Better to keep adapting it then stay static and annoying. |
Okay, tagged 1.3.0. |
@alecthomas @FrankStain As an aside I think usage of |
Ahhh I see, haha it's always right after you finish a response :P Specialising for aggregates would ease the backwards compatibility issues as any current code won't use brace initialisation as this is reserved only for aggregates. |
Don't worry about backwards compatibility. |
This is why I am using |
Huh, interesting that that PR was all it took. I'll update later and make my code a lot shorter :) |
Why was it reverted? Couldn’t find any explanation |
entityx/entityx/Entity.h
Line 648 in 6389b1f
Seems like the line I've tagged could be easily changed to use brace initialisation rather than direct initialisation. I'm wondering if this has been considered previously and any reason for the choice to avoid it.
Brace initialisation would allow for aggregate initialisation meaning that you don't need to manually create a constructor for each component. Given that components should frequently qualify as aggregates this would seem to be a nice improvement by removing the need to create constructors unnecessarily.
Thoughts?
The text was updated successfully, but these errors were encountered: