fork(2) download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <vector>
  4.  
  5. struct A
  6. {
  7. A() { std::cout << "Default" << std::endl; }
  8. A(A&&) noexcept { std::cout << "Move" << std::endl; }
  9. A(const A&) { std::cout << "Copy" << std::endl; }
  10. };
  11.  
  12. template <typename T, typename...U>
  13. std::vector<std::decay_t<T>> make_vector(T&& t, U&&...u)
  14. {
  15. std::vector<std::decay_t<T>> v;
  16. v.emplace_back(std::forward<T>(t));
  17. std::initializer_list<int>{(v.emplace_back(std::forward<U>(u)), 0)...};
  18. return v;
  19. }
  20.  
  21. int main()
  22. {
  23. const A a1;
  24. A a2;
  25. auto v = make_vector(A(), a1, std::move(a2));
  26. }
  27.  
  28.  
  29.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Default
Default
Default
Move
Copy
Move
Move
Move
Move