Skip to content

Instantly share code, notes, and snippets.

@mattn
Created July 30, 2010 04:20
Show Gist options
  • Save mattn/499895 to your computer and use it in GitHub Desktop.
Save mattn/499895 to your computer and use it in GitHub Desktop.
// g++ -std=c++0x cxx0x-deferred.cxx
#include <iostream>
template <typename T>
class Deferred {
private:
T r;
public:
Deferred() {}
Deferred(T v) : r(v) {}
Deferred& next(T(*f)(T)) { r = f(r); return *this; }
Deferred& loop(unsigned int c, void(*f)(int)) {
for (unsigned int n = 0; n < c; n++) f(n);
return *this;
}
};
int main() {
Deferred<bool>(true)
.next([&](bool a){
std::cout << (a ? "true" : "false") << std::endl;
return true;
})
.loop(3, [&](int n){
std::cout << n << std::endl;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment