Projects > cpp > Issues > Feature #2525

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

Create Issue on Github

Add Iterator object of cocos2d::Array

Feature #2525 [Closed]
ricardo 2013-08-13 18:31 . Updated over 3 years ago

Array should support iterators, including begin() and end().

If we add that, the trantision to v3.0 will be much easier, since it won’t matter if we use Array of std::vector or any other container.

And we should deprecate the macro CCARRAY_FOREACH.

Users should be able to do something like this:

auto children = layer.getChildren();

for( auto child : children )
  child.setPosition( Point(10,10) );

And that code should ALWAYS work. It should not depend if we use Array, or std::vector or std::list or any other container.

ricardo 2013-08-13 18:33
  • Description updated (diff)
ricardo 2013-08-13 18:34
  • Assignee set to zhangxm
  • Priority changed from Normal to High
ricardo 2013-08-13 18:36
  • Project changed from cocos2d-x to cpp
ricardo 2013-08-13 18:37
  • Target version set to 3.0-alpha0
ricardo 2013-08-13 18:56
  • Tracker changed from Feature to Refactor
ricardo 2013-08-13 18:56
  • Tracker changed from Refactor to Feature
zhangxm 2013-08-14 03:25

CCArray is not a template, it can contain a Object* in it, but it doesn’t know the real type of the element. So should be used it like this

auto children = layer.getChildren();

for( auto child : children )  
{
  Node *node = static_cast(child);
  node->setPosition( Point(10,10) ); // the return type is Object*, don't know the real type.
}
ricardo 2013-08-14 03:41

Minggo Zhang wrote:

CCArray is not a template, it can contain a Object* in it, but it doesn’t know the real type of the element. So should be used it like this
[…]

good point. Yes, it is accetable to force a cast to Node* objects like in your example.

zhangxm 2013-08-22 03:37
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Atom PDF

Status:Closed
Start date:2013-08-13
Priority:High
Due date:
Assignee:zhangxm
% Done:

100%

Category:all
Target version:3.0-alpha0

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.