Skip to content

Instantly share code, notes, and snippets.

@Pet3ris
Created May 30, 2011 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pet3ris/999358 to your computer and use it in GitHub Desktop.
Save Pet3ris/999358 to your computer and use it in GitHub Desktop.
C++ FOR macro
Old macro for use in programming competitions. Iterates over numbers and iterators, choosing the right comparison for each range.
template <class T, bool B> struct cmp_ { inline static bool cmp(T a, T b) { return a < b; } };
template <class T> struct cmp_<T, false> { inline static bool cmp(T a, T b) { return a != b; } };
#define FOR(i, b, e) for (typeof(b) i = (b); cmp_< typeof(b), numeric_limits< typeof(b) >::is_specialized >::cmp(i, e); ++i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment