use more constexpr
This commit is contained in:
parent
63f467081a
commit
aac30a27e7
|
@ -19,11 +19,11 @@ class Window;
|
||||||
|
|
||||||
struct BufferCoord : LineAndColumn<BufferCoord>
|
struct BufferCoord : LineAndColumn<BufferCoord>
|
||||||
{
|
{
|
||||||
BufferCoord(LineCount line = 0, CharCount column = 0)
|
constexpr BufferCoord(LineCount line = 0, CharCount column = 0)
|
||||||
: LineAndColumn(line, column) {}
|
: LineAndColumn(line, column) {}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
explicit BufferCoord(const LineAndColumn<T>& other)
|
explicit constexpr BufferCoord(const LineAndColumn<T>& other)
|
||||||
: LineAndColumn(other.line, other.column) {}
|
: LineAndColumn(other.line, other.column) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,11 @@ namespace Kakoune
|
||||||
|
|
||||||
struct DisplayCoord : LineAndColumn<DisplayCoord>
|
struct DisplayCoord : LineAndColumn<DisplayCoord>
|
||||||
{
|
{
|
||||||
DisplayCoord(LineCount line = 0, CharCount column = 0)
|
constexpr DisplayCoord(LineCount line = 0, CharCount column = 0)
|
||||||
: LineAndColumn(line, column) {}
|
: LineAndColumn(line, column) {}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
explicit DisplayCoord(const LineAndColumn<T>& other)
|
explicit constexpr DisplayCoord(const LineAndColumn<T>& other)
|
||||||
: LineAndColumn(other.line, other.column) {}
|
: LineAndColumn(other.line, other.column) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,10 @@ struct Key
|
||||||
Modifiers modifiers;
|
Modifiers modifiers;
|
||||||
Character key;
|
Character key;
|
||||||
|
|
||||||
Key(Modifiers modifiers, Character key)
|
constexpr Key(Modifiers modifiers, Character key)
|
||||||
: modifiers(modifiers), key(key) {}
|
: modifiers(modifiers), key(key) {}
|
||||||
|
|
||||||
bool operator==(const Key& other) const
|
constexpr bool operator==(const Key& other) const
|
||||||
{ return modifiers == other.modifiers and key == other.key; }
|
{ return modifiers == other.modifiers and key == other.key; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,22 +12,22 @@ struct LineAndColumn
|
||||||
LineCount line;
|
LineCount line;
|
||||||
CharCount column;
|
CharCount column;
|
||||||
|
|
||||||
LineAndColumn(LineCount line = 0, CharCount column = 0)
|
constexpr LineAndColumn(LineCount line = 0, CharCount column = 0)
|
||||||
: line(line), column(column) {}
|
: line(line), column(column) {}
|
||||||
|
|
||||||
EffectiveType operator+(const EffectiveType& other) const
|
constexpr EffectiveType operator+(const EffectiveType& other) const
|
||||||
{
|
{
|
||||||
return EffectiveType(line + other.line, column + other.column);
|
return EffectiveType(line + other.line, column + other.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectiveType& operator+=(const EffectiveType& other)
|
constexpr EffectiveType& operator+=(const EffectiveType& other)
|
||||||
{
|
{
|
||||||
line += other.line;
|
line += other.line;
|
||||||
column += other.column;
|
column += other.column;
|
||||||
return *static_cast<EffectiveType*>(this);
|
return *static_cast<EffectiveType*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectiveType operator-(const EffectiveType& other) const
|
constexpr EffectiveType operator-(const EffectiveType& other) const
|
||||||
{
|
{
|
||||||
return EffectiveType(line - other.line, column - other.column);
|
return EffectiveType(line - other.line, column - other.column);
|
||||||
}
|
}
|
||||||
|
@ -39,40 +39,36 @@ struct LineAndColumn
|
||||||
return *static_cast<EffectiveType*>(this);
|
return *static_cast<EffectiveType*>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator< (const EffectiveType& other) const
|
constexpr bool operator< (const EffectiveType& other) const
|
||||||
{
|
{
|
||||||
if (line != other.line)
|
return (line != other.line) ? line < other.line
|
||||||
return line < other.line;
|
: column < other.column;
|
||||||
return column < other.column;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<= (const EffectiveType& other) const
|
constexpr bool operator<= (const EffectiveType& other) const
|
||||||
{
|
{
|
||||||
if (line != other.line)
|
return (line != other.line) ? line < other.line
|
||||||
return line < other.line;
|
: column <= other.column;
|
||||||
return column <= other.column;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator> (const EffectiveType& other) const
|
constexpr bool operator> (const EffectiveType& other) const
|
||||||
{
|
{
|
||||||
if (line != other.line)
|
return (line != other.line) ? line > other.line
|
||||||
return line > other.line;
|
: column > other.column;
|
||||||
return column > other.column;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator>= (const EffectiveType& other) const
|
constexpr bool operator>= (const EffectiveType& other) const
|
||||||
{
|
{
|
||||||
if (line != other.line)
|
return (line != other.line) ? line > other.line
|
||||||
return line > other.line;
|
: column >= other.column;
|
||||||
return column >= other.column;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator== (const EffectiveType& other) const
|
constexpr bool operator== (const EffectiveType& other) const
|
||||||
{
|
{
|
||||||
return line == other.line and column == other.column;
|
return line == other.line and column == other.column;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!= (const EffectiveType& other) const
|
constexpr bool operator!= (const EffectiveType& other) const
|
||||||
{
|
{
|
||||||
return line != other.line or column != other.column;
|
return line != other.line or column != other.column;
|
||||||
}
|
}
|
||||||
|
|
36
src/units.hh
36
src/units.hh
|
@ -8,19 +8,19 @@ template<typename RealType, typename ValueType = int>
|
||||||
class StronglyTypedInteger
|
class StronglyTypedInteger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit StronglyTypedInteger(ValueType value)
|
explicit constexpr StronglyTypedInteger(ValueType value)
|
||||||
: m_value(value) {}
|
: m_value(value) {}
|
||||||
|
|
||||||
RealType operator+(const RealType& other) const
|
constexpr RealType operator+(const RealType& other) const
|
||||||
{ return RealType(m_value + other.m_value); }
|
{ return RealType(m_value + other.m_value); }
|
||||||
|
|
||||||
RealType operator-(const RealType& other) const
|
constexpr RealType operator-(const RealType& other) const
|
||||||
{ return RealType(m_value - other.m_value); }
|
{ return RealType(m_value - other.m_value); }
|
||||||
|
|
||||||
RealType operator*(const RealType& other) const
|
constexpr RealType operator*(const RealType& other) const
|
||||||
{ return RealType(m_value * other.m_value); }
|
{ return RealType(m_value * other.m_value); }
|
||||||
|
|
||||||
RealType operator/(const RealType& other) const
|
constexpr RealType operator/(const RealType& other) const
|
||||||
{ return RealType(m_value / other.m_value); }
|
{ return RealType(m_value / other.m_value); }
|
||||||
|
|
||||||
RealType& operator+=(const RealType& other)
|
RealType& operator+=(const RealType& other)
|
||||||
|
@ -47,50 +47,50 @@ public:
|
||||||
RealType operator--(int)
|
RealType operator--(int)
|
||||||
{ RealType backup(*this); --m_value; return backup; }
|
{ RealType backup(*this); --m_value; return backup; }
|
||||||
|
|
||||||
RealType operator-() { return RealType(-m_value); }
|
constexpr RealType operator-() { return RealType(-m_value); }
|
||||||
|
|
||||||
bool operator==(const RealType& other) const
|
constexpr bool operator==(const RealType& other) const
|
||||||
{ return m_value == other.m_value; }
|
{ return m_value == other.m_value; }
|
||||||
|
|
||||||
bool operator!=(const RealType& other) const
|
constexpr bool operator!=(const RealType& other) const
|
||||||
{ return m_value != other.m_value; }
|
{ return m_value != other.m_value; }
|
||||||
|
|
||||||
bool operator<(const RealType& other) const
|
constexpr bool operator<(const RealType& other) const
|
||||||
{ return m_value < other.m_value; }
|
{ return m_value < other.m_value; }
|
||||||
|
|
||||||
bool operator<=(const RealType& other) const
|
constexpr bool operator<=(const RealType& other) const
|
||||||
{ return m_value <= other.m_value; }
|
{ return m_value <= other.m_value; }
|
||||||
|
|
||||||
bool operator>(const RealType& other) const
|
constexpr bool operator>(const RealType& other) const
|
||||||
{ return m_value > other.m_value; }
|
{ return m_value > other.m_value; }
|
||||||
|
|
||||||
bool operator>=(const RealType& other) const
|
constexpr bool operator>=(const RealType& other) const
|
||||||
{ return m_value >= other.m_value; }
|
{ return m_value >= other.m_value; }
|
||||||
|
|
||||||
bool operator!() const
|
constexpr bool operator!() const
|
||||||
{ return !m_value; }
|
{ return !m_value; }
|
||||||
|
|
||||||
explicit operator ValueType() const { return m_value; }
|
explicit constexpr operator ValueType() const { return m_value; }
|
||||||
private:
|
private:
|
||||||
ValueType m_value;
|
ValueType m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LineCount : public StronglyTypedInteger<LineCount, int>
|
struct LineCount : public StronglyTypedInteger<LineCount, int>
|
||||||
{
|
{
|
||||||
LineCount(int value) : StronglyTypedInteger<LineCount>(value) {}
|
constexpr LineCount(int value) : StronglyTypedInteger<LineCount>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline LineCount operator"" _line(unsigned long long int value)
|
inline constexpr LineCount operator"" _line(unsigned long long int value)
|
||||||
{
|
{
|
||||||
return LineCount(value);
|
return LineCount(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CharCount : public StronglyTypedInteger<CharCount, int>
|
struct CharCount : public StronglyTypedInteger<CharCount, int>
|
||||||
{
|
{
|
||||||
CharCount(int value) : StronglyTypedInteger<CharCount>(value) {}
|
constexpr CharCount(int value) : StronglyTypedInteger<CharCount>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline CharCount operator"" _char(unsigned long long int value)
|
inline constexpr CharCount operator"" _char(unsigned long long int value)
|
||||||
{
|
{
|
||||||
return CharCount(value);
|
return CharCount(value);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user