fork(1) download
  1. #include <iostream>
  2.  
  3. template <typename Function>
  4. class storage
  5. {
  6. public:
  7. storage(const Function & function) : m_function(function)
  8. {
  9. std::cout << m_function(1) << '\n';
  10. }
  11.  
  12. storage(Function && function) : m_function(std::move(function))
  13. {
  14. std::cout << m_function(1) << '\n';
  15. }
  16.  
  17. private:
  18. Function m_function;
  19. };
  20.  
  21. int f(int x)
  22. {
  23. return x + 1;
  24. }
  25.  
  26. int main()
  27. {
  28. storage<int(*)(int)> storage_f_ptr(f);
  29.  
  30. auto g = [](int y) { return 11*y; };
  31. storage<decltype(g)> storage_g_lambda(g);
  32.  
  33. }
  34.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
2
11