#pragma once #include #include namespace fc { template class signal { public: typedef int64_t connection_id_type; template connection_id_type connect( Functor&& f ) { auto c = new std::function( fc::forward(f) ); _handlers.push_back( c ); return reinterpret_cast(c); } template void emit( Args&&... args ) { for( size_t i = 0; i < _handlers.size(); ++i ) { (*_handlers[i])( args... ); } } template void operator()( Args&&... args ) { for( size_t i = 0; i < _handlers.size(); ++i ) { (*_handlers[i])( args... ); } } void disconnect( connection_id_type cid ) { auto itr = _handlers.begin(); while( itr != _handlers.end() ) { if( reinterpret_cast(*itr) == cid ) { delete *itr; _handlers.erase(itr); } ++itr; } } private: fc::vector< std::function* > _handlers; }; }