88#include < cstddef> // std::size_t
99#include < string> // std::string
1010#include < cstring> // std::memcmp
11- #include < exception> // std::exception
11+ #include < stdexcept> // std::runtime_error
12+ #include < utility> // std::exchange
1213
1314namespace bmp {
1415 // Magic number for Bitmap .bmp 24 bpp files (24/8 = 3 = rgb colors only)
@@ -50,10 +51,10 @@ namespace bmp {
5051 constexpr Pixel (std::uint8_t red, std::uint8_t green, std::uint8_t blue) noexcept : r(red), g(green), b(blue) {}
5152
5253 constexpr bool operator ==(const Pixel other) const noexcept {
53- return r == other.r and g == other.g and b == other.b ;
54+ return r == other.r && g == other.g && b == other.b ;
5455 }
5556
56- constexpr bool operator !=(const Pixel other) const noexcept { return not ((*this ) == other); }
57+ constexpr bool operator !=(const Pixel other) const noexcept { return ! ((*this ) == other); }
5758 };
5859
5960 static_assert (sizeof (Pixel) == 3 , " Bitmap Pixel size must be 3 bytes" );
@@ -124,6 +125,12 @@ namespace bmp {
124125
125126 Bitmap (const Bitmap &other) = default; // Copy Constructor
126127
128+ Bitmap (Bitmap &&other) noexcept
129+ : m_pixels(std::move(other.m_pixels)),
130+ m_width(std::exchange(other.m_width, 0 )),
131+ m_height(std::exchange(other.m_height, 0 )) {
132+ }
133+
127134 virtual ~Bitmap () noexcept {
128135 m_pixels.clear ();
129136 }
@@ -400,7 +407,7 @@ namespace bmp {
400407
401408 bool operator !=(const Bitmap &image) const { return !(*this == image); }
402409
403- Bitmap &operator =(const Bitmap &image) // Move assignment operator
410+ Bitmap &operator =(const Bitmap &image) // Copy assignment operator
404411 {
405412 if (this != &image) {
406413 m_width = image.m_width ;
@@ -410,6 +417,15 @@ namespace bmp {
410417 return *this ;
411418 }
412419
420+ Bitmap &operator =(Bitmap &&image) noexcept {
421+ if (this != &image) {
422+ m_pixels = std::move (image.m_pixels );
423+ m_width = std::exchange (image.m_width , 0 );
424+ m_height = std::exchange (image.m_height , 0 );
425+ }
426+ return *this ;
427+ }
428+
413429 public: /* * foreach iterators access */
414430 std::vector<Pixel>::iterator begin () noexcept { return m_pixels.begin (); }
415431
0 commit comments