#include <iostream>
#include <functional>
template<class R,class derived> class Base;
template<class F>
class AnyFunction:public Base<typename std::function<F>::result_type,AnyFunction<F>>{
std::function<F> Fun;
public:
typedef typename std::function<F>::result_type RT;
AnyFunction(std::function<F> Function){
Fun = Function;
}
RT DoFunction(typename std::function<F>::argument_type&& Arge){
return Fun(Arge);
}
};
template<class R,class Derived>
class Base
{
public:
typedef R RT;
public:
template<class ...Arges>
RT operator()(Arges&& ... Arge){
return static_cast<Derived*>(this)->DoFunction(Arge...);
}
};
int main(){
AnyFunction<int(int&)> AF([](int& N)->int{std::cout <<"Calling Lambada!"<< std::endl; return N; });
int N = AF(10);
std::cout << AF(10) << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KCnRlbXBsYXRlPGNsYXNzIFIsY2xhc3MgZGVyaXZlZD4gY2xhc3MgQmFzZTsKdGVtcGxhdGU8Y2xhc3MgRj4KY2xhc3MgQW55RnVuY3Rpb246cHVibGljIEJhc2U8dHlwZW5hbWUgc3RkOjpmdW5jdGlvbjxGPjo6cmVzdWx0X3R5cGUsQW55RnVuY3Rpb248Rj4+ewoJc3RkOjpmdW5jdGlvbjxGPiBGdW47CnB1YmxpYzoKCgl0eXBlZGVmIHR5cGVuYW1lIHN0ZDo6ZnVuY3Rpb248Rj46OnJlc3VsdF90eXBlIFJUOwoKCUFueUZ1bmN0aW9uKHN0ZDo6ZnVuY3Rpb248Rj4gRnVuY3Rpb24pewoJCUZ1biA9IEZ1bmN0aW9uOwoJfQoKCVJUIERvRnVuY3Rpb24odHlwZW5hbWUgc3RkOjpmdW5jdGlvbjxGPjo6YXJndW1lbnRfdHlwZSYmIEFyZ2UpewoJCXJldHVybiBGdW4oQXJnZSk7Cgl9Cgp9OwoKdGVtcGxhdGU8Y2xhc3MgUixjbGFzcyBEZXJpdmVkPgpjbGFzcyBCYXNlCnsKCnB1YmxpYzoKCgl0eXBlZGVmIFIgUlQ7CnB1Ymx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