Skip to content

Instantly share code, notes, and snippets.

@ssube
Created November 11, 2011 11:06
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 ssube/1357751 to your computer and use it in GitHub Desktop.
Save ssube/1357751 to your computer and use it in GitHub Desktop.
// v1
#define loop(x,op,y) (auto t=x; for(auto c=y;c>1;--c){t=t op;},t)
//v2
#define rdo(x,op,y) ([&](){auto t=x;auto r=y;while(r){t=t op;};return t;})()
//v3
#define rdo(x,op,y) (auto l=[=](){auto t=x;auto r=y;while(r){t=t op;};return t;},l())
//v4
#define rdo(x,op,y) (auto l=[=](){auto t=x;auto r=y;while(r){t=t op;--r};return t;},l())
printf("%d", rdo(2,*2,2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment