Created
February 10, 2012 16:32
-
-
Save jorendorff/1790659 to your computer and use it in GitHub Desktop.
C++ APIs for Iteration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *** 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