Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

Copy Assignment

##Copy Assignment CheckingChecking for self assignment in copy assignment.

Move Assignment

##Move Assignment TheThe standard approach is what you commented out swapping

##Move Constructor

Move Constructor

##Copy Assignment Checking for self assignment in copy assignment.

##Move Assignment The standard approach is what you commented out swapping

##Move Constructor

Copy Assignment

Checking for self assignment in copy assignment.

Move Assignment

The standard approach is what you commented out swapping

Move Constructor

deleted 22 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
class MemoryBlock
{
public:
 explicit MemoryBlock(const int l = 0)
 : lengthsize{l}
 , data{new int[l]}
 {}
 MemoryBlock(MemoryBlock const& rhs)
 : lengthsize{rhs.lengthsize}
 , data{new int[rhs.length]size]}
 {
 std::copy(rhs.data, rhs.data + lengthsize, data);
 } 
 MemoryBlock& operator=(MemoryBlock const& rhs)
 {
 MemoryBlock copy(rhs);
 copy.swap(*this);
 return *this;
 }
 MemoryBlock(MemoryBlock&& rhs) noexcept
 : lengthsize{0}
 , data{nullptr}
 {
 rhs.swap(*this);
 }
 MemoryBlock& operator=(MemoryBlock&& rhs) noexcept
 {
 rhs.swap(*this);
 return *this;
 }
 void swap(MemoryBlock& rhs) noexcept
 {
 using std::swap;
 swap(lengthsize, rhs.lengthsize);
 swap(data, rhs.data);
 }
 friend void swap(MemoryBlock& lhs, MemoryBlock& rhs)
 {
 rhs.swap(lhs);
 }
 ~MemoryBlock()
 {
 delete [] data;
 }
 int length() const
 {
 return length;size;
 }
private:
 int length;size;
 int* data;
};
class MemoryBlock
{
public:
 explicit MemoryBlock(const int l = 0)
 : length{l}
 , data{new int[l]}
 {}
 MemoryBlock(MemoryBlock const& rhs)
 : length{rhs.length}
 , data{new int[rhs.length]}
 {
 std::copy(rhs.data, rhs.data + length, data);
 } 
 MemoryBlock& operator=(MemoryBlock const& rhs)
 {
 MemoryBlock copy(rhs);
 copy.swap(*this);
 return *this;
 }
 MemoryBlock(MemoryBlock&& rhs) noexcept
 : length{0}
 , data{nullptr}
 {
 rhs.swap(*this);
 }
 MemoryBlock& operator=(MemoryBlock&& rhs) noexcept
 {
 rhs.swap(*this);
 return *this;
 }
 void swap(MemoryBlock& rhs) noexcept
 {
 using std::swap;
 swap(length, rhs.length);
 swap(data, rhs.data);
 }
 friend void swap(MemoryBlock& lhs, MemoryBlock& rhs)
 {
 rhs.swap(lhs);
 }
 ~MemoryBlock()
 {
 delete [] data;
 }
 int length() const
 {
 return length;
 }
private:
 int length;
 int* data;
};
class MemoryBlock
{
public:
 explicit MemoryBlock(const int l = 0)
 : size{l}
 , data{new int[l]}
 {}
 MemoryBlock(MemoryBlock const& rhs)
 : size{rhs.size}
 , data{new int[rhs.size]}
 {
 std::copy(rhs.data, rhs.data + size, data);
 } 
 MemoryBlock& operator=(MemoryBlock const& rhs)
 {
 MemoryBlock copy(rhs);
 copy.swap(*this);
 return *this;
 }
 MemoryBlock(MemoryBlock&& rhs) noexcept
 : size{0}
 , data{nullptr}
 {
 rhs.swap(*this);
 }
 MemoryBlock& operator=(MemoryBlock&& rhs) noexcept
 {
 rhs.swap(*this);
 return *this;
 }
 void swap(MemoryBlock& rhs) noexcept
 {
 using std::swap;
 swap(size, rhs.size);
 swap(data, rhs.data);
 }
 friend void swap(MemoryBlock& lhs, MemoryBlock& rhs)
 {
 rhs.swap(lhs);
 }
 ~MemoryBlock()
 {
 delete [] data;
 }
 int length() const
 {
 return size;
 }
private:
 int size;
 int* data;
};
added 37 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
class MemoryBlock
{
public:
 explicit MemoryBlock(const int l = 0)
 : length{l}
 , data{new int[l]}
 {}
 MemoryBlock(constMemoryBlock MemoryBlock&const& rhs)
 : length{rhs.length}
 , data{new int[rhs.length]}
 {
 std::copy(rhs.data, rhs.data + length, data);
 } 
 MemoryBlock& operator=(constMemoryBlock MemoryBlock&const& rhs)
 {
 MemoryBlock copy(rhs);
 copy.swap(*this);
 return *this;
 }
 MemoryBlock(MemoryBlock&& rhs) noexcept
 : length{0}
 , data{nullptr}
 {
 rhs.swap(*this);
 }
 MemoryBlock& operator=(MemoryBlock&& rhs) noexcept
 {
 rhs.swap(*this);
 return *this;
 }
 void swap(MemoryBlock& rhs) noexcept
 {
 using std::swap;
 swap(length, rhs.length);
 swap(data, rhs.data);
 }
 friend void swap(MemoryBlock& lhs, MemoryBlock& rhs)
 {
 rhs.swap(lhs);
 }
 ~MemoryBlock()
 {
 delete [] data;
 }
 int length() const
 {
 return length;
 }
private:
 int length;
 int* data;
};
class MemoryBlock
{
public:
 explicit MemoryBlock(const int l = 0)
 : length{l}
 , data{new int[l]}
 {}
 MemoryBlock(const MemoryBlock& rhs)
 : length{rhs.length}
 , data{new int[rhs.length]}
 {
 std::copy(rhs.data, rhs.data + length, data);
 } 
 MemoryBlock& operator=(const MemoryBlock& rhs)
 {
 rhs.swap(*this);
 return *this;
 }
 MemoryBlock(MemoryBlock&& rhs) noexcept
 : length{0}
 , data{nullptr}
 {
 rhs.swap(*this);
 }
 MemoryBlock& operator=(MemoryBlock&& rhs) noexcept
 {
 rhs.swap(*this);
 return *this;
 }
 void swap(MemoryBlock& rhs) noexcept
 {
 using std::swap;
 swap(length, rhs.length);
 swap(data, rhs.data);
 }
 friend void swap(MemoryBlock& lhs, MemoryBlock& rhs)
 {
 rhs.swap(lhs);
 }
 ~MemoryBlock()
 {
 delete [] data;
 }
 int length() const
 {
 return length;
 }
private:
 int length;
 int* data;
};
class MemoryBlock
{
public:
 explicit MemoryBlock(const int l = 0)
 : length{l}
 , data{new int[l]}
 {}
 MemoryBlock(MemoryBlock const& rhs)
 : length{rhs.length}
 , data{new int[rhs.length]}
 {
 std::copy(rhs.data, rhs.data + length, data);
 } 
 MemoryBlock& operator=(MemoryBlock const& rhs)
 {
 MemoryBlock copy(rhs);
 copy.swap(*this);
 return *this;
 }
 MemoryBlock(MemoryBlock&& rhs) noexcept
 : length{0}
 , data{nullptr}
 {
 rhs.swap(*this);
 }
 MemoryBlock& operator=(MemoryBlock&& rhs) noexcept
 {
 rhs.swap(*this);
 return *this;
 }
 void swap(MemoryBlock& rhs) noexcept
 {
 using std::swap;
 swap(length, rhs.length);
 swap(data, rhs.data);
 }
 friend void swap(MemoryBlock& lhs, MemoryBlock& rhs)
 {
 rhs.swap(lhs);
 }
 ~MemoryBlock()
 {
 delete [] data;
 }
 int length() const
 {
 return length;
 }
private:
 int length;
 int* data;
};
deleted 2 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading
added 1642 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /