libutil: replace Pos operator< with <=> and constexpr ==

Change-Id: I60080c416b2ee2b0efce4584cf13f37c0596d73d
This commit is contained in:
Qyriad
2025-11-07 12:07:23 +01:00
parent f00d720d83
commit f39cbc5d60
2 changed files with 9 additions and 9 deletions
-6
View File
@@ -17,12 +17,6 @@ Pos::operator std::shared_ptr<Pos>() const
return std::make_shared<Pos>(&*this);
}
bool Pos::operator<(const Pos &rhs) const
{
return std::forward_as_tuple(line, column, origin)
< std::forward_as_tuple(rhs.line, rhs.column, rhs.origin);
}
std::optional<LinesOfCode> Pos::getCodeLines() const
{
if (line == 0)
+9 -3
View File
@@ -67,9 +67,15 @@ struct Pos
std::optional<LinesOfCode> getCodeLines() const;
bool operator==(const Pos & rhs) const = default;
bool operator!=(const Pos & rhs) const = default;
bool operator<(const Pos & rhs) const;
// Not defaulted because it's implicitly deleted because C++ is stupid.
constexpr friend auto operator<=>(Pos const & lhs, Pos const & rhs)
{
return std::forward_as_tuple(lhs.line, lhs.column, lhs.origin)
<=> std::forward_as_tuple(rhs.line, rhs.column, rhs.origin);
}
// operator<=> doesn't generate this because it's not defaulted.
constexpr friend bool operator==(Pos const & lhs, Pos const & rhs) = default;
struct LinesIterator {
using difference_type = size_t;