Adjust Iterator API to be more simple to implement and simpler to generate code for.
With the current (Pike 8.0) iterator API, the iterator starts at the first item, which means that foreach()
needs to do something like:
if (!!(iter)) { // Calls lfun::`!().
do {
mixed ind = iter->index();
mixed val = iter->value();
// Body
} while (iter->next());
}
Changing it so that iterators start before the first item simplifies the code:
while(iter->_iterator_next()) {
mixed ind = iter->_iterator_index();
mixed val = iter->_iterator_value();
// Body
}
Also consider supporting having _iterator_next()
return the current index if there is no _iterator_index()
.
Note that this change naturally requires having the compiler add a backward compat implementation of _iterator_next()
for old-style iterators.