Advertisement
Guest User

Function

a guest
Sep 28th, 2015
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. template <typename R>
  2. class MultiFuncObject
  3. {
  4.     unordered_map<type_index, void(*)()> m_funcs;
  5. public:
  6.  
  7.     template <typename ...A1>
  8.     MultiFuncObject<R> operator +=(R(*f)(A1...))
  9.     {
  10.         m_funcs[typeid(R(A1...))] = (void(*)()) f;
  11.         return *this;
  12.     }
  13.  
  14.  
  15.     template <typename ...A1>
  16.     R operator()(A1... a1) const
  17.     {
  18.         unordered_map<type_index, void(*)()>::const_iterator it = m_funcs.find(typeid(R(A1...)));
  19.         if (it != m_funcs.end())
  20.         {
  21.             R(*f)(A1...) = (R(*)(A1...))(it->second);
  22.             (*f)(a1...);
  23.         }
  24.     }
  25.  
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement