Skip to content

Instantly share code, notes, and snippets.

@jorendorff
Created February 10, 2012 16:32
Show Gist options
  • Save jorendorff/1790659 to your computer and use it in GitHub Desktop.
Save jorendorff/1790659 to your computer and use it in GitHub Desktop.
C++ APIs for Iteration
// *** design #1
if (!forOf(cx, obj, [cx] (const Value &v) {
...
})) {
return false;
}
// *** design #2
for (IterationRange it(cx, obj); !it.empty(); it.popFront()) {
... it.front() ...
}
if (!it.good())
return false;
// *** design #3
Iteration it;
if (!it.start(cx, obj))
return false;
for (;;) {
Value val;
if (!it.next(&val))
return false; // error - already close()d and discarded the iterator
if (val.isMagic(BREAK))
break; // StopIteration - already close()d and discarded the iterator
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment