#include <iostream>
#include <memory>
#include <type_traits>

template <class F>
struct Decomposer;

template <class R, class A>
struct Decomposer<R (A)>
{
  typedef R return_type;
  typedef A argument_type;
};


template <class F>
struct my_function
{
  typedef typename Decomposer<F>::return_type return_type;
  typedef typename Decomposer<F>::argument_type argument_type;
  
  return_type operator() (argument_type arg) const {
  	return (*impl)(arg);
  }
  
  template <class From>
  my_function(From &&from)
  {
  	struct ConcreteImpl : Impl
  	{
  		typename std::remove_reference<From>::type functor;
  		ConcreteImpl(From &&functor) : functor(std::forward<From>(functor)) {}
  		virtual return_type operator() (argument_type arg) const override
  		{
  			return functor(arg);
  		}
  	};
  	impl.reset(new ConcreteImpl(std::forward<From>(from)));
  }

private:
  struct Impl {
  	virtual ~Impl() {}
  	virtual return_type operator() (argument_type arg) const = 0;
  };
  
  std::unique_ptr<Impl> impl;
};


int main(int argc, char* argv[])
{
    int mybool = 5;

    auto foo = [&] (int arg) {
        return mybool * arg;
    };

    my_function<int(int)> foo2 = foo;

    int result = foo2(42);
    
    std::cout << result << std::endl;

    return 0;
}