Created
February 11, 2015 11:55
-
-
Save vlastachu/a83f5a4ca4d222d5fe88 to your computer and use it in GitHub Desktop.
kawaii c++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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