fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <memory>
  4. #include <type_traits>
  5.  
  6. template <typename T>
  7. void
  8. fill_list(std::list<T> &l, T &&e)
  9. {
  10. l.push_back(std::move(e));
  11. }
  12.  
  13. template <typename T, typename... Args>
  14. void
  15. fill_list(std::list<T> &l, T &&e, Args... args)
  16. {
  17. l.push_back(std::move(e));
  18. fill_list(l, std::move(args)...);
  19. }
  20.  
  21. int
  22. main(void)
  23. {
  24. std::list<std::unique_ptr<int>> ints;
  25. fill_list(ints,
  26. std::unique_ptr<int>(new int(9)),
  27. std::unique_ptr<int>(new int(66)));
  28.  
  29. std::cout << *ints.front() << std::endl;
  30. std::cout << *ints.back() << std::endl;
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
9
66