fork(1) download
  1. #include <memory>
  2. #include <utility>
  3. #include <string>
  4. #include <cassert>
  5.  
  6. enum GLenum { foo };
  7.  
  8. // this class doesn't have any default, copy constructors.
  9. struct Dep
  10. {
  11. Dep(std::string path, GLenum type) {}
  12. Dep() = delete;
  13. Dep(Dep const&) = delete;
  14. };
  15.  
  16. struct Program
  17. {
  18. std::shared_ptr<Dep> dep1;
  19. std::shared_ptr<Dep> dep2;
  20.  
  21. #if 1
  22. template <class T, class = typename std::enable_if<std::is_constructible<std::shared_ptr<Dep>, T>::value>::type>
  23. Program(T&& dep1, T&& dep2)
  24. : dep1(std::forward<T>(dep1)), dep2(std::forward<T>(dep2))
  25. {
  26. }
  27. #else
  28. Program(std::shared_ptr<Dep> dep1, std::shared_ptr<Dep> dep2)
  29. : dep1(std::move(dep1)), dep2(std::move(dep2))
  30. {
  31. }
  32. #endif
  33. };
  34.  
  35. int main()
  36. {
  37. auto dep1 = std::make_shared<Dep>("dep1", foo);
  38. auto dep2 = std::make_shared<Dep>("dep2", foo);
  39. Program p(std::move(dep1), std::move(dep2));
  40.  
  41. assert(!dep1 && !dep2);
  42. }
  43.  
  44.  
Success #stdin #stdout 0s 3016KB
stdin
Standard input is empty
stdout
Standard output is empty