fork download
  1. #include <iostream>
  2. #include <initializer_list>
  3. #include <vector>
  4. #include <utility>
  5.  
  6. struct Obj
  7. {
  8. Obj() {
  9. std::cout << __PRETTY_FUNCTION__ << std::endl;
  10. }
  11. Obj(Obj&&) {
  12. std::cout << __PRETTY_FUNCTION__ << std::endl;
  13. }
  14. Obj(Obj const &) {
  15. std::cout << __PRETTY_FUNCTION__ << std::endl;
  16. }
  17.  
  18. Obj& operator=(Obj&&) = default;
  19. Obj& operator=(Obj const &) = delete;
  20. };
  21.  
  22. template <class T>
  23. std::vector<T> make_vector(std::initializer_list<T> lst) {
  24. std::vector<T> result;
  25. result.reserve(lst.size());
  26. for(const T& item: lst) {
  27. T& item2 = const_cast<T&>(item);
  28. result.emplace_back(std::move(item2));
  29. }
  30. return result;
  31. }
  32.  
  33.  
  34. int main() {
  35. auto a = Obj();
  36. std::cout << "---" << std::endl << std::endl;
  37. make_vector({ a, Obj(), Obj() });
  38. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Obj::Obj()
---

Obj::Obj(const Obj&)
Obj::Obj()
Obj::Obj()
Obj::Obj(Obj&&)
Obj::Obj(Obj&&)
Obj::Obj(Obj&&)