Skip to content

Instantly share code, notes, and snippets.

@mwhittaker
Created March 28, 2014 01:48
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 mwhittaker/9823369 to your computer and use it in GitHub Desktop.
Save mwhittaker/9823369 to your computer and use it in GitHub Desktop.
Simple C++ Bind
#include <iostream>
#include <vector>
template<typename F>
int operator>>=(int i, F f) {
if (i == 0) {
return i;
}
return f(i);
}
int main() {
auto f = [](int i) {
return i >>= [](int i) {
return i * 2 >>= [](int i) {
return i * 3 >>= [](int i) {
return 100 / i;
};};};};
std::vector<int> v = {0,1,2,3,4};
for (const int& x : v) {
std::cout << "f(" << x << ") = " << f(x) << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment