Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct Functor
- {
- int operator()(int a, int b)
- {
- std::cout << "Calling functor with " << a << " and " << b << std::endl;
- return a + b;
- }
- };
- template<class T>
- T make_instance();
- template<class T>
- struct LogAnyFunctor : public T
- {
- template<typename... Args>
- auto operator()(Args... args) -> decltype(make_instance<T>()(args...))
- {
- std::cout << "Before" << std::endl;
- int res = T::operator()(args...);
- std::cout << "After" << std::endl;
- return res;
- }
- };
- int main()
- {
- LogAnyFunctor<Functor> a;
- std::cout << a(2, 3) << std::endl;
- }
Add Comment
Please, Sign In to add comment