New C*+ standard have many features that can simplify usage of cocos2d-x. Since C*+ 2011 support is almost complete on android, iOS, Mac OS X and recent Linux distributions, can we discuss it?
There are also perfomance boost from rvalue refs, but since cocos2d-x uses raw pointers, I don’t expect noticeable effect (may be rvalues can increase perfomance for smart pointers and geometry classes, since return-value optimization can be impossible for cocos2d-x compiled as shared library or as static library without LTO in compiler settings).
Non-static member initialization.
CC_SYNTHESIZE/CC_PROPERTY creates property that should be also explicitly initialized in constructor. With non-static member initialization it can be changed to initialize value automatically: just expand macro to
int memberVar = 0;. There are two cons:
* variable still keeps garbage for compilers without C++ 2011 support (GCC before 4.7 and Visual Studio).
* not all types can be initialized with zero. Problem can be eliminated by GCC/clang extension which allows to determine macro parameter type.
* it simplifies async operations (i.e. all code for several threads can be written inside one function, like in Objective-C with blocks).
* it simplifies delayed operations, usually performed by CCSequence which contains CCDelayTime and CCCallFunc.
* std::function available only on modern compilers versions, so cocos2d-x should hide such features under macro like CC_COMPILER_HAS_LAMBDAS and user code becomes not so portable (to Windows).
foreach loop for CCArray * and maybe CCDictionary/CCSet.
* Can be achieved with simple adaptor class: https://github.com/sergey-shambir/cocos2d-x-extensions-cpp2011
* should be hidden under macro CC_COMPILER_HAS_RANGE_FOR
* For data structures, can replace create(CCAction , …), so user will never forget to add NULL at end.
should be hidden under macro CC_COMPILER_HAS_INITIALIZER_LISTS
override and final attributes
* Can be wrapped by macro CC_OVERRIDE and CC_FINAL
* can be used inside cocos2d-x to speed up some operations, for example, at weak references counting mechanism.