#ifndef _FC_FUNCTION_HPP_ #define _FC_FUNCTION_HPP_ #include #include /* #include #include namespace fc { // place holder for more compile-effecient functor #if !defined(BOOST_NO_TEMPLATE_ALIASES) template using function = std::function; #else #endif */ //template //class function { }; namespace fc { template class function_impl { public: template function_impl( Functor&& f ) :func( new impl( fc::forward(f) ) ){}; function_impl( const function_impl& c ):func(c.func){} function_impl( function_impl&& c ) { fc::swap( func, c.func); } ~function_impl(){} template function_impl& operator=( Functor&& f ) { func.reset( new impl( fc::forward(f) ) ); return *this; } function_impl& operator=( const function_impl& c ) { func = c.func; return *this; } function_impl& operator=( function_impl&& c ) { fc::swap(func,c.func); return *this; } template R operator()( Args2... args2) { return func->call(fc::forward(args2)...); } private: struct impl_base : public fc::retainable { virtual ~impl_base(){} virtual R call(Args...) = 0; }; template struct impl : impl_base { template impl( U&& u ):func( fc::forward(u) ){} virtual R call(Args... args) { return func(args...); } Functor func; }; 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. */ template class function : public function_impl { public: template function( U&& u ):function_impl( fc::forward(u) ){} using function_impl::operator=; }; template class function : public function_impl { public: template function( U&& u ):function_impl( fc::forward(u) ){} using function_impl::operator=; }; template class function : public function_impl { public: template function( U&& u ):function_impl( fc::forward(u) ){} using function_impl::operator=; }; template class function : public function_impl { public: template function( U&& u ):function_impl( fc::forward(u) ){} using function_impl::operator=; }; } #endif // _FC_FUNCTION_HPP_