Checked: Use default compiler-generated functions

Problem:
- Compiler-generated functions are being defined which results in
  extra code to maintain.

Solution:
- Switch to compiler-generated default functions for default
  construction, copy assignment, move assignment, copy construction
  and move construction.
This commit is contained in:
Lenny Maiorani 2020-10-19 09:11:00 -04:00 committed by Andreas Kling
parent b4790010a8
commit bd99083436
Notes: sideshowbarker 2024-07-19 01:50:13 +09:00

View file

@ -112,10 +112,7 @@ inline constexpr bool is_within_range(Source value)
template<typename T> template<typename T>
class Checked { class Checked {
public: public:
Checked() Checked() = default;
: m_value(0)
{
}
Checked(T value) Checked(T value)
: m_value(value) : m_value(value)
@ -129,11 +126,7 @@ public:
m_value = value; m_value = value;
} }
Checked(const Checked& other) Checked(const Checked&) = default;
: m_value(other.m_value)
, m_overflow(other.m_overflow)
{
}
Checked(Checked&& other) Checked(Checked&& other)
: m_value(exchange(other.m_value, 0)) : m_value(exchange(other.m_value, 0))
@ -147,12 +140,7 @@ public:
return *this = Checked(value); return *this = Checked(value);
} }
Checked& operator=(const Checked& other) Checked& operator=(const Checked& other) = default;
{
m_value = other.value();
m_overflow = other.m_overflow;
return *this;
}
Checked& operator=(Checked&& other) Checked& operator=(Checked&& other)
{ {
@ -272,7 +260,7 @@ public:
} }
private: private:
T m_value; T m_value {};
bool m_overflow { false }; bool m_overflow { false };
}; };