Last active
December 18, 2015 04:58
-
-
Save octavifs/5728879 to your computer and use it in GitHub Desktop.
foreach C++ macro. Takes a variable (will be an iterator. Don't instantiate!) and a container.
Salvaged from http://stackoverflow.com/a/197926.
This file contains 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
// Usage: | |
// foreach(it, container) { | |
// CONTAINER_VALUE_TYPE v = *it | |
// ... | |
// } | |
// | |
#ifndef FOREACH_MACRO | |
#define FOREACH_MACRO | |
#define VAR(V,init) __typeof(init) V=(init) | |
#define FOREACH(I,C) for(VAR(I,(C).begin());I!=(C).end();I++) | |
#define foreach(I, C) FOREACH(I,C) | |
#endif FOREACH_MACRO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment