fork download
  1. #include <iostream>
  2.  
  3. template<typename T>
  4. struct test_t{
  5. T value;
  6.  
  7. test_t(){
  8. std::cerr << __PRETTY_FUNCTION__ << '\n';
  9. }
  10.  
  11. template<typename X>
  12. test_t(X&& val) : value{std::forward<X>(val)}{
  13. std::cerr << __PRETTY_FUNCTION__ << '\n';
  14. }
  15.  
  16. template<typename X>
  17. test_t(const test_t<X>& rhs) : value{rhs.value}{
  18. std::cerr << __PRETTY_FUNCTION__ << '\n';
  19. }
  20.  
  21. template<typename X>
  22. test_t& operator= (const test_t<X>& rhs){
  23. std::cerr << __PRETTY_FUNCTION__ << '\n';
  24. value = rhs.value;
  25. return *this;
  26. }
  27.  
  28. template<typename X>
  29. test_t(test_t<X>&& rhs) : value{std::move(rhs.value)}{
  30. std::cerr << __PRETTY_FUNCTION__ << '\n';
  31. }
  32.  
  33. template<typename X>
  34. test_t& operator= (test_t<X>&& rhs){
  35. std::cerr << __PRETTY_FUNCTION__ << '\n';
  36. value = std::move(rhs.value);
  37. return *this;
  38. }
  39.  
  40. ~test_t(){
  41. std::cerr << __PRETTY_FUNCTION__ << '\n';
  42. }
  43. };
  44.  
  45.  
  46. #include <vector>
  47.  
  48. int main(){
  49. std::vector<test_t<int>> container;
  50.  
  51. for(int n=0; n!=3; ++n) {
  52. std::cout << n << '\n';
  53. container.emplace_back();
  54. }
  55. }
  56.  
Success #stdin #stdout #stderr 0s 15240KB
stdin
Standard input is empty
stdout
0
1
2
stderr
test_t<T>::test_t() [with T = int]
test_t<T>::test_t() [with T = int]
test_t<T>::~test_t() [with T = int]
test_t<T>::test_t() [with T = int]
test_t<T>::~test_t() [with T = int]
test_t<T>::~test_t() [with T = int]
test_t<T>::~test_t() [with T = int]
test_t<T>::~test_t() [with T = int]
test_t<T>::~test_t() [with T = int]