Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- template <typename TFunc>
- struct carry;
- template <typename TResult, typename TFirstParam, typename... TOthers>
- struct carry<TResult (TFirstParam, TOthers...)> {
- carry(std::function<TResult (TFirstParam, TOthers...)> f_): f(move(f_)) {}
- auto operator ()(TFirstParam para) -> carry<TResult (TOthers...)> {
- return carry<TResult (TOthers...)>([=] (TOthers... args) {
- return f(para, args...);
- });
- }
- std::function<TResult (TFirstParam, TOthers...)> f;
- };
- template <typename TResult, typename TFirstParam>
- struct carry<TResult (TFirstParam)> {
- carry(std::function<TResult (TFirstParam)> f_): f(move(f_)) {}
- TResult operator ()(TFirstParam para) {
- return f(para);
- }
- std::function<TResult (TFirstParam)> f;
- };
- int main(void)
- {
- using namespace std;
- carry<int(int, int, int, int)> f([] (int a, int b, int c, int d) { return a+b+c+d; });
- cout << f(1)(2)(3)(4);
- }
Advertisement
Add Comment
Please, Sign In to add comment