Skip to content

Instantly share code, notes, and snippets.

@vlastachu
Created February 11, 2015 11:55
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 vlastachu/a83f5a4ca4d222d5fe88 to your computer and use it in GitHub Desktop.
Save vlastachu/a83f5a4ca4d222d5fe88 to your computer and use it in GitHub Desktop.
kawaii c++
// http://ideone.com/ZmrJtE
#include <iostream>
#include <functional>
using namespace std;
using namespace std::placeholders;
template <typename A, typename B, typename C>
function<C(B)> operator^(A a, function<C(A,B)> fun){
return bind(fun, a, _1); //partial application
}
template <typename B, typename C>
C operator^(function<C(B)> fun, B b){
return fun(b);
}
int main(int, char**)
{
//it seems impossible to get std::function with generic type or type inference at place
//probably second (type inference) we may get with boost make_function(function)
std::function<string(string,string)> __ = [](auto a, auto b){return a + " ^_^ " + b;};
string a = "a", b = "b", c = "c";
cout << (a ^__^ b ^__^ c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment