fork(1) download
  1. #include <iostream>
  2. #include <utility>
  3. #include <functional>
  4.  
  5. using namespace std;
  6.  
  7. // -----------------------------------------------
  8. template<typename T, typename F>
  9. struct Test
  10. {
  11. T m_resource;
  12. F m_deleter;
  13.  
  14. Test(T&& resource, F&& deleter)
  15. : m_resource(move(resource)), m_deleter(move(deleter))
  16. {
  17. }
  18. Test(T const& resource, F const& deleter)
  19. : m_resource(resource), m_deleter(deleter)
  20. {
  21. }
  22. };
  23. // -----------------------------------------------
  24.  
  25. // -----------------------------------------------
  26. template<typename T, typename F>
  27. Test<T, F> test(T&& t, F&& f)
  28. {
  29. return Test<T, F>(move(t), move(f));
  30. }
  31. template<typename T, typename F>
  32. Test<T, F> test(T const& t, F const& f)
  33. {
  34. return Test<T, F>(t, f);
  35. }
  36. // -----------------------------------------------
  37.  
  38. int main()
  39. {
  40. // construct from temporaries --------------------
  41. Test<int*, function<void(int*)>> t(new int, [](int *k) {}); // OK - constructor
  42. auto tm = test(new int, [](int *k){}); // OK - maker function
  43. // -----------------------------------------------
  44.  
  45. // construct from l-values -----------------------
  46. int *N = new int(24);
  47. auto F = function<void(int*)>([](int *k){});
  48.  
  49. Test<int*, function<void(int*)>> tt(N, F); // OK - construction
  50. //auto m = test(N, F); // Error - maker function
  51. // -----------------------------------------------
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty