Skip to content

Instantly share code, notes, and snippets.

@mrkn
Created February 25, 2011 07:26
Show Gist options
  • Save mrkn/843470 to your computer and use it in GitHub Desktop.
Save mrkn/843470 to your computer and use it in GitHub Desktop.
int main(int argc, char** argv) { return 0; }
#include <iostream>
using namespace std;
template<class Cond, class Expr>
struct While {
While(Cond& cond, Expr& expr)
{
while (cond()) expr();
}
};
struct CountDown {
CountDown(long ini)
: current_(ini)
{}
bool operator()()
{
return --current_ > 0;
}
private:
long current_;
};
struct Hello {
void operator()()
{
std::cout << "hello world." << std::endl;
}
};
CountDown ten_times(10);
Hello hello;
While<CountDown, Hello> w(ten_times, hello);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment