Skip to content

Commit ac79c03

Browse files
committed
More use of auto instead of explicit std::strong_ordering.
1 parent 07a1ba6 commit ac79c03

9 files changed

Lines changed: 23 additions & 29 deletions

File tree

libs/basic/charbuf.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,11 @@ class CharBufBase {
4545
CharBufBase & operator+=(std::string_view str) { return append(str); }
4646
CharBufBase & operator+=(const CharBufBase & src) { return append(src); }
4747

48-
std::strong_ordering operator<=>(const CharBufBase & right) const {
49-
return compare(right);
50-
}
51-
std::strong_ordering operator<=>(std::string_view right) const {
52-
return compare(right);
53-
}
54-
std::strong_ordering operator<=>(const char right[]) const {
48+
auto operator<=>(const CharBufBase & right) const {
5549
return compare(right);
5650
}
51+
auto operator<=>(std::string_view right) const { return compare(right); }
52+
auto operator<=>(const char right[]) const { return compare(right); }
5753

5854
bool operator==(const CharBufBase & right) const {
5955
return compare(right) == 0;

libs/basic/intset.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class IntegralSet {
153153
// compare
154154
std::strong_ordering compare(const IntegralSet & other) const;
155155
std::strong_ordering operator<=>(const IntegralSet & other) const;
156-
bool operator==(const IntegralSet & right) const;
156+
bool operator==(const IntegralSet & other) const;
157157

158158
// search
159159
value_type front() const;
@@ -181,9 +181,9 @@ class IntegralSet {
181181
private:
182182
friend std::ostream & operator<<(
183183
std::ostream & os,
184-
const IntegralSet & right
184+
const IntegralSet & val
185185
) {
186-
if (auto v = right.ranges().begin()) {
186+
if (auto v = val.ranges().begin()) {
187187
for (;;) {
188188
os << v->first;
189189
if (auto len = v->second - v->first) {

libs/basic/types.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ struct VersionInfo {
6565
unsigned patch;
6666
unsigned build;
6767

68-
bool operator==(const VersionInfo &) const = default;
69-
std::strong_ordering operator<=>(const VersionInfo &) const = default;
68+
auto operator<=>(const VersionInfo &) const = default;
7069
explicit operator bool() const { return *this != VersionInfo{}; }
7170
};
7271

libs/net/address.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,8 @@ size_t std::hash<SubnetAddr>::operator()(const SubnetAddr & val) const {
265265
hashCombine(&out, std::hash<int>{}(val.prefixLen));
266266
return out;
267267
}
268+
269+
//===========================================================================
270+
SubnetAddr::operator bool() const {
271+
return prefixLen || addr;
272+
}

libs/net/address.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct HostAddr {
8585
// Sets to "::FFFF.a.b.c.d" format
8686
uint32_t ipv4(uint32_t addr);
8787

88-
std::strong_ordering operator<=>(const HostAddr & right) const = default;
88+
auto operator<=>(const HostAddr & right) const = default;
8989
explicit operator bool() const;
9090

9191
private:
@@ -97,7 +97,7 @@ struct SockAddr {
9797
HostAddr addr;
9898
unsigned port = {};
9999

100-
std::strong_ordering operator<=>(const SockAddr & right) const = default;
100+
auto operator<=>(const SockAddr & right) const = default;
101101
explicit operator bool() const;
102102

103103
private:
@@ -109,6 +109,9 @@ struct SubnetAddr {
109109
HostAddr addr;
110110
unsigned prefixLen = {};
111111

112+
auto operator<=>(const SubnetAddr & right) const = default;
113+
explicit operator bool() const;
114+
112115
private:
113116
friend std::ostream & operator<<(
114117
std::ostream & os,

libs/net/httproute.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ const unordered_map<string_view, MimeType> s_mimeTypeMap = []() {
588588
}();
589589

590590
//===========================================================================
591-
strong_ordering MimeType::operator<=>(const MimeType & other) const {
591+
auto MimeType::operator<=>(const MimeType & other) const {
592592
return fileExt <=> other.fileExt;
593593
}
594594

libs/net/httproute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ struct MimeType {
339339
std::string_view type;
340340
std::string_view charSet;
341341

342-
std::strong_ordering operator<=>(const MimeType & other) const;
342+
auto operator<=>(const MimeType & other) const;
343343
bool operator==(const MimeType & other) const = default;
344344
};
345345
MimeType mimeTypeDefault(std::string_view path);

tools/cmtupd/cmtupd.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@ struct Action {
5454

5555
strong_ordering operator<=>(const Action & other) const {
5656
// Lowest type first.
57-
auto rc = reportType <=> other.reportType;
58-
if (rc == 0) {
59-
// Best (lowest) priority first.
60-
rc = reportPriority <=> other.reportPriority;
61-
}
62-
return rc;
57+
return tie(reportType, reportPriority) <=>
58+
tie(other.reportType, other.reportPriority);
6359
}
6460
};
6561
const TokenTable::Token s_actionTypes[] = {
@@ -95,7 +91,7 @@ struct Config {
9591
struct Count {
9692
const Action * act;
9793
unsigned count = {};
98-
strong_ordering operator<=>(const Count & other) const {
94+
auto operator<=>(const Count & other) const {
9995
return *act <=> *other.act;
10096
}
10197
};

tools/pargen/intern.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ struct Element {
7575
std::string eventName; // only present if different from name
7676

7777
auto operator<=>(const Element & right) const {
78-
if (auto cmp = name.compare(right.name)) {
79-
return cmp < 0
80-
? std::strong_ordering::less
81-
: std::strong_ordering::greater;
82-
}
83-
return std::strong_ordering::equal;
78+
return name <=> right.name;
8479
}
8580

8681
private:

0 commit comments

Comments
 (0)