Advertisement
tinyevil

Untitled

Aug 5th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.28 KB | None | 0 0
  1. template<class Evt>
  2. class Multicast{
  3. public:
  4.     template<class Fn>
  5.     void addObserver(Fn&& obs){
  6.         observers.push_back(obs);
  7.     }
  8.    
  9.     void broadcast(Evt event){
  10.         for ( auto& obs : observers ){
  11.             obs(event);
  12.         }
  13.     }
  14. private:
  15.     std::vector< std::function<void(Evt)> > observers;
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement