Guest User

Untitled

a guest
Oct 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct Functor
  4. {
  5.         int operator()(int a, int b)
  6.         {
  7.                 std::cout << "Calling functor with " << a << " and " << b << std::endl;
  8.                 return a + b;
  9.         }
  10. };
  11.  
  12. template<class T>
  13. T make_instance();
  14.  
  15. template<class T>
  16. struct LogAnyFunctor : public T
  17. {
  18.         template<typename... Args>
  19.         auto operator()(Args... args) -> decltype(make_instance<T>()(args...))
  20.         {
  21.                 std::cout << "Before" << std::endl;
  22.                 int res = T::operator()(args...);
  23.                 std::cout << "After" << std::endl;
  24.                 return res;
  25.         }
  26. };
  27.  
  28.  
  29. int main()
  30. {
  31.         LogAnyFunctor<Functor> a;
  32.         std::cout << a(2, 3) << std::endl;
  33. }
Add Comment
Please, Sign In to add comment