fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. using namespace std;
  5.  
  6. class Me {};
  7.  
  8. using TGetter = std::function<std::string( Me* )>;
  9.  
  10. std::string getter( Me* me )
  11. {
  12. return std::string( "string" );
  13. }
  14.  
  15. template<typename TGetter>
  16. class Handler
  17. {
  18.  
  19. public:
  20. using TValue = typename TGetter::result_type;
  21. Handler( TGetter getter ) :m_getter( getter ) {}
  22. TValue get()
  23. {
  24. Me m;
  25. return m_getter( &m );
  26. }
  27.  
  28. private:
  29. TGetter m_getter;
  30. };
  31.  
  32. int main()
  33. {
  34. using MyHanlder = Handler<TGetter>;
  35. MyHanlder h(getter);
  36. MyHanlder::TValue s = h.get();
  37. cout << s;
  38. }
Success #stdin #stdout 0s 4516KB
stdin
Standard input is empty
stdout
string