Using STL collections on cocos2d-x v3.0

Using STL collections on cocos2d-x v3.0
0.0 0



i’d like to suggest to use STL containers like std::vector, std::map, std::set… over Array, Dictionary, Set…

I know it’s main drawback would be losing the retain, release mechanism, but we’d gain strong typing (something we shouldn’t have lost in a C++ framework).
One should not be casting everything from Object but having it directly (or almost) at it’s concrete type.

I only saying that strong typed languages must be strong typed, nothing else :stuck_out_tongue:


I’m agree. Note that there is task that needs weak typing: it’s property list loading. However, it can be done without CCObject subclasses or unsafe pointers (pointers are safe in ObjC due to nil object feature), like Qt QVariant/QVariantList/QVariantMap classes.

Retain/release mechanism can be saved with smart pointer (similar to shared pointer, but does not use special chunk of memory to store reference count). It complicates type signature a bit: user should write std::vector<StrongPtr<Node>> instead of CCArray *. However, in such case user doesn’t need in typecasts and retain/release for array itself.


Thanks. Yes, using stl containers is one of the things that we would like to do. We are still doing some research.