Projects > cpp > Issues > Bug #2790

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Templated containers

Bug #2790 [Closed]
ricardo 2013-09-10 18:28 . Updated over 11 years ago

cocos2d-x has Dictionary, Array, Set an other containers. They are handy but they are not very C*+ friendly.
C*+ is an static language by design, and being static has many benefits (performance for example, compiler warnings, etc).

For that reason we need templated containers, like the std ones.

For example:

  • cocos2d::Vector<T>
  • cocos2d::Map<T>

Ideally, we should define Array and Dictionary as:

typedef Vector Array;
typedef Map Dictionary;

… but I think it won’t be possible since cocos2d::Map and cocos2d::Vector should be able to be created on the stack: no create functions for these objects… also, they should not inherit from Object.

The different between std::map<> and cocos2d::Map<> is that cocos2d::Map<> MUST work with ref counted objects. It will do retain / release for all the objects.

zhangxm 2013-09-11 02:19
  • Assignee set to boyu0
zhangxm 2013-09-16 12:24
  • Priority changed from Normal to High
  • Target version changed from 3.0-alpha0 to Candidate
zhangxm 2013-09-28 03:16
  • Target version changed from Candidate to 3.0-alpha1
zhangxm 2013-11-15 03:34
  • Target version changed from 3.0-alpha1 to 3.0-beta
ricardo 2013-11-21 22:14

Yes, we need this ASAP. It will make our code more readable and we will detect bugs easier.

It will also change the API a bit… eg: the macro CC_ARRAY_FOREACH() might no longer be valid… although we can make it work if we convert it to use the new C++11 iterator API.

zhangxm 2013-11-26 08:24
  • Assignee changed from boyu0 to dumganhar
dumganhar 2013-11-26 09:08

they should not inherit from Object.

If the new containers don’t inherit from Object, we will not be able to pull a Vector to another Vector or value of Map.
In this way, the compatibility will be broken since cocos2d::Array and cocos2d::Dictionary are inherited from Object which reference counted.
They could be used in a nested.

dumganhar 2013-11-26 09:11

Could you let me know why new containers should not inherit from Object?
It also could work on stack if it inherits from Object.

dumganhar 2013-12-20 08:19
  • Status changed from New to Resolved
zhangxm 2013-12-27 14:00
  • Status changed from Resolved to Closed

Atom PDF

Status:Closed
Start date:2013-09-10
Priority:High
Due date:
Assignee:dumganhar
% Done:

0%

Category:all
Target version:3.0-beta