fork download
  1. #include <type_traits>
  2.  
  3. template <typename T>
  4. class smart_ptr
  5. {
  6. public:
  7. // ... removed other member functions for simplicity
  8. T* get() const { return ptr; }
  9.  
  10. private:
  11. template <typename... Args>
  12. struct opparen_constret
  13. {
  14. typedef decltype(std::declval<T const>()(std::declval<Args>()...)) type;
  15. };
  16.  
  17. template <typename... Args>
  18. struct opparen_ret
  19. {
  20. typedef decltype(std::declval<T>()(std::declval<Args>()...)) type;
  21. };
  22.  
  23. public:
  24. template <typename... Args>
  25. typename opparen_constret<Args...>::type operator ()(Args... args) const
  26. {
  27. return (*get())(args...);
  28. }
  29.  
  30. template <typename... Args>
  31. typename opparen_ret<Args...>::type operator ()(Args... args)
  32. {
  33. return (*get())(args...);
  34. }
  35.  
  36. private:
  37. T* ptr;
  38. };
  39.  
  40. struct Test {};
  41.  
  42. int main()
  43. {
  44. smart_ptr<Test> p;
  45. return 0;
  46. }
Success #stdin #stdout 0s 2880KB
stdin
Standard input is empty
stdout

Standard output is empty