fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. template<class T0> struct value_wrapper {
  6.  
  7. value_wrapper( T0* data_ ) {
  8. std::cout << "value_wrapper( T0* data_ )" << std::endl;
  9. data = data_;
  10. }
  11.  
  12. value_wrapper() {
  13. std::cout << "value_wrapper()" << std::endl;
  14. data = new T0{};
  15. }
  16.  
  17. value_wrapper( const value_wrapper& other ) {
  18. std::cout << "value_wrapper( const value_wrapper& other )" << std::endl;
  19. data = new T0{};
  20. *data = *other.data;
  21. }
  22.  
  23. value_wrapper& operator=( const value_wrapper& other ) {
  24. std::cout << "value_wrapper& operator=( const value_wrapper& other )" << std::endl;
  25. *data = *other.data;
  26. }
  27.  
  28. ~value_wrapper() {
  29. std::cout << "~value_wrapper()" << std::endl;
  30. delete data;
  31. }
  32.  
  33. //move construction and assigment, other operators and member functions
  34.  
  35. T0* data;
  36. };
  37.  
  38. //test class
  39. struct value {
  40. value() { std::cout << "value()" << std::endl; }
  41. value( const value& other ) { std::cout << "value( const value& other )" << std::endl; }
  42. value& operator=( const value& other ) { std::cout << "value& operator=( const value& other )" << std::endl; }
  43. ~value() { std::cout << "~value()" << std::endl; }
  44. };
  45.  
  46.  
  47. int main() {
  48. value_wrapper<value> v1{ new value{} };
  49. value_wrapper<value> v2{};
  50. v2 = v1;
  51. }
  52.  
  53.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
value()
value_wrapper( T0* data_ )
value_wrapper()
value()
value_wrapper& operator=( const value_wrapper& other )
value& operator=( const value& other )
~value_wrapper()
~value()
~value_wrapper()
~value()