#if 0 #pragma once #include #include namespace fc { template class function { public: function(){} template function( Functor&& f ) :func( new impl( fc::forward(f) ) ){}; function( const function& c ):func(c.func){} function( function&& c ) { fc::swap( func, c.func); } ~function(){} template function& operator=( Functor&& f ) { func.reset( new impl( fc::forward(f) ) ); return *this; } function& operator=( const function& c ) { func = c.func; return *this; } function& operator=( function&& c ) { fc::swap(func,c.func); return *this; } R operator()( Args... args)const { return func->call(args...); } bool operator!()const { return !func; } protected: struct impl_base : public fc::retainable { virtual ~impl_base(){} virtual R call(Args...)const = 0; }; template struct impl : impl_base { template impl( U&& u ):func( fc::forward(u) ){} virtual R call(Args... args)const { return func(args...); } Functor func; }; function( const fc::shared_ptr& f ):func(f){} function( fc::shared_ptr&& f ):func(fc::move(f)){} fc::shared_ptr func; }; /** * Provides functionality similar to boost::function. * * Functions have 'reference semantics', meaning that copies will all * refer to the same underlying function. * * TODO: Small functions are allocated on the stack, large functors are * allocated on the heap. * * Simply including boost/function adds an additional 0.6 seconds to every * object file compared to using fc/function. * * Including on the other hand adds a mere 0.05 * seconds to every object file compared to fc/function. */ template class function : public function { public: function(){} template function( U&& u ) { *this = fc::forward(u); } using function::operator=; }; template class function : public function { public: function(){} function( const function& u ):function(u){} function( function&& u ):function(u){} function( const function& u ):function(u.func){} function( function&& u ):function(fc::move(u.func)){} using function::operator=; }; template class function : public function { public: function(){} template function( U&& u ):function( fc::forward(u) ){} function( const function& c ):function(c.func){} using function::operator=; }; template class function : public function { public: function(){} template function( U&& u ):function( fc::forward(u) ){} function( const function& c ):function(c.func){} using function::operator=; }; } #endif