mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Add constexpr to TriStateBool class
This commit is contained in:
parent
54e486c389
commit
b813a878d7
2 changed files with 21 additions and 32 deletions
|
@ -31,28 +31,3 @@
|
||||||
const TriStateBool TriStateBool::Undefined(-1);
|
const TriStateBool TriStateBool::Undefined(-1);
|
||||||
const TriStateBool TriStateBool::False(0);
|
const TriStateBool TriStateBool::False(0);
|
||||||
const TriStateBool TriStateBool::True(1);
|
const TriStateBool TriStateBool::True(1);
|
||||||
|
|
||||||
TriStateBool::operator int() const
|
|
||||||
{
|
|
||||||
return m_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
TriStateBool::TriStateBool(int value)
|
|
||||||
{
|
|
||||||
if (value < 0)
|
|
||||||
m_value = -1;
|
|
||||||
else if (value > 0)
|
|
||||||
m_value = 1;
|
|
||||||
else
|
|
||||||
m_value = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TriStateBool::operator==(const TriStateBool &other) const
|
|
||||||
{
|
|
||||||
return (m_value == other.m_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TriStateBool::operator!=(const TriStateBool &other) const
|
|
||||||
{
|
|
||||||
return !operator==(other);
|
|
||||||
}
|
|
||||||
|
|
|
@ -36,15 +36,29 @@ public:
|
||||||
static const TriStateBool False;
|
static const TriStateBool False;
|
||||||
static const TriStateBool True;
|
static const TriStateBool True;
|
||||||
|
|
||||||
TriStateBool() = default;
|
constexpr TriStateBool() = default;
|
||||||
TriStateBool(const TriStateBool &other) = default;
|
constexpr TriStateBool(const TriStateBool &other) = default;
|
||||||
|
explicit constexpr TriStateBool(int value)
|
||||||
|
: m_value(value < 0 ? -1 : (value > 0 ? 1 : 0))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
explicit TriStateBool(int value);
|
explicit constexpr operator int() const
|
||||||
explicit operator int() const;
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
TriStateBool &operator=(const TriStateBool &other) = default;
|
TriStateBool &operator=(const TriStateBool &other) = default; // add constexpr when using C++14
|
||||||
bool operator==(const TriStateBool &other) const;
|
|
||||||
bool operator!=(const TriStateBool &other) const;
|
constexpr bool operator==(const TriStateBool &other) const
|
||||||
|
{
|
||||||
|
return (m_value == other.m_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool operator!=(const TriStateBool &other) const
|
||||||
|
{
|
||||||
|
return !operator==(other);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
signed char m_value = -1; // Undefined by default
|
signed char m_value = -1; // Undefined by default
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue