Sign in to follow this  
Jason Goepel

Move Constructors/Assignment

Recommended Posts

Jason Goepel    797

Have you given any thought toward C++11-style move constructors and assignment for AngelScript?  It would be quite useful to be able to register something like opAssign(MyClass&& a)  or opAssign(MyClass&temp a). 

Share this post


Link to post
Share on other sites
WitchLord    4677

C++11 brought many interesting improvements to the C++ language, but right now there are so many other things to do AngelScript before I get to implement enhancements targeted at C++11 that it will likely take a very long time before I get to these.

Share this post


Link to post
Share on other sites
InvalidPointer    1842

As interesting as these would be, I *strongly* question whether or not something like this belongs in a game scripting language. Move semantics, as implemented in C++, solve a C++-specific design shortcoming, and I think the best way to approach this is to solve things at a higher level. There's a reason C++ code is bloody murder to reason about.

Share this post


Link to post
Share on other sites
Jason Goepel    797

I appreciate that it could take a very long time to get to implementing such a feature.  I only ask to see if it is part of your vision or not.

 

Concerning whether or not such a thing belongs in a game scripting language, I have a Matrix class which I desire to have "value assignment" characteristics.

A = B will copy B to A, not simply add a reference to B and assign a pointer to A.  Also, we all know it is most convenient for a function to "return" its result, particularly if one wants to chain together operations.

B = A.Transpose().Invert() 

rather than:

A.Transpose(temp);
temp.Invert(B);
 

The first syntax also avoids the need to do some parameter checking, like whether or not the destination object is equal to "this".

A.Transpose(A)  // Maybe not a good idea 

With the combination of the above concepts, any return from a function requires an unnecessary copy.  Some of my users' matrices have thousands of rows, so I would like to avoid extra copying.

Share this post


Link to post
Share on other sites
WitchLord    4677

I agree with both of you.

 

The script writer should definitely not have to bother with move operators or normal copy operators (unless he really wants to), he/she should just write the code as quickly as possible. 

 

But there is certainly nothing wrong with allowing the application to provide a more performatic API to the script engine, which is where the enhancement to AngelScript comes in. In order to take advantage of the new temp reference && in C++, the engine will need to know the difference between a temp reference and a normal reference when registering the interface. The compiler must also be enhanced to keep track of which references are to temporary objects or not so that it call call the appropriate function.

 

It is quite likely that I'll add this support in the future. Though as it is essentially an optimization feature, and probably only useable with C++11 capable compilers it will definitely be prioritized at the moment.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this