Тема: ContainerIterator
Показать сообщение отдельно
Старый 13.02.2008, 17:00   #18  
Андре is offline
Андре
Moderator
Сотрудники компании GMCS
 
2,375 / 464 (20) +++++++
Регистрация: 03.12.2001
Кстати, если к containerEnumerator добавить один метод:
X++:
public container enumerate()
{
    return [idx, conpeek(con, idx)];
}
то можно имитировать Python - ий enumerate():
X++:
items = ['a','b']
for i,thing in enumerate(items):
     print 'index',i,'contains',thing
То есть, вместо громоздкого:
X++:
int  idx;
;
while(enumerator.moveNext())
{
     idx++;
     value = enumerator.current();
}
писать изящное:
X++:
int  idx;
;
while(enumerator.moveNext())
{
     [idx, value] = enumerator.enumerate();
}
Вложения
Тип файла: xpo gm_containerEnumerator.xpo (1.5 Кб, 578 просмотров)