Builtin range/collection type

Started by
1 comment, last by _Vicious_ 10 years, 2 months ago

Hello fellow AngelScripters,

now that we have 'auto' keyword support thanks to GGLucas ( http://www.gamedev.net/topic/652525-experimental-patches-named-arguments-and-auto-declarations/ ) maybe we could start thinking on how it'd be best to implement iteratable ranges/collection types in AS? For example, it'd be nice to be able to iterate in the following manner:


uint maxPlayers;
...
for( auto playerIndex : range<int>(0,maxPlayers-1) ) {

or even


array <Player @> players;
...
for( auto @Player : players ) {

I'm using C++11 syntax here but there might be other alternatives.

Any thoughts or suggestions?

Advertisement

The most difficult part of this is to create safe iterators. The implementation of the iterators must guarantee a proper behaviour even if the object that is being iterated is modified from somewhere else while it is being iterated.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

It appears to me that deleting or inserting an element in collection preceeding the iterator internal pointer should increment or decrement the pointer accordingly. Iterator should also hold reference to the collection and the currently pointed element too if it's refcounted. Nothing else has come to my mind so far.

This topic is closed to new replies.

Advertisement