fork(1) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory>
  4. using namespace std;
  5.  
  6. struct Integer
  7. {
  8. explicit Integer( int const &value )
  9. : value_( value )
  10. {
  11. }
  12. Integer()
  13. :value_( 0 )
  14. {
  15. }
  16. Integer &operator=( int const &value )
  17. {
  18. cout << value << endl;
  19. value_ = value;
  20. return *this;
  21. }
  22. private:
  23. int value_;
  24. };
  25.  
  26. template<class _Ty>
  27. struct Array
  28. {
  29. explicit Array( size_t const &size, _Ty const &value )
  30. : size_( size ), elements_( new _Ty[ size ] )
  31. {
  32. for( size_t i = 0; i < size; i++ )
  33. *( elements_ + i ) = value;
  34. }
  35. ~Array()
  36. {
  37. if( elements_ )
  38. delete[]elements_;
  39. elements_ = 0;
  40. size_ = 0;
  41. }
  42. private:
  43. _Ty *elements_;
  44. size_t size_;
  45. };
  46.  
  47. int main()
  48. {
  49. Integer i( 15 );
  50.  
  51. auto value = std::make_unique< Array<Integer> >( 10, i );
  52.  
  53. i = 16;
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
16