Skip to content

Commit 95c70dd

Browse files
committed
Use C++20 default comparisons for section objects
1 parent f7ebb6b commit 95c70dd

File tree

3 files changed

+4
-68
lines changed

3 files changed

+4
-68
lines changed

src/section_data.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ struct section_num
1010
{
1111
std::string prefix;
1212
std::vector<int> num;
13+
14+
auto operator<=>(const section_num&) const = default;
1315
};
1416

1517
std::istream&
@@ -82,30 +84,6 @@ operator << (std::ostream& os, const section_num& sn)
8284
return os;
8385
}
8486

85-
bool
86-
operator<(const section_num& x, const section_num& y)
87-
{
88-
if (x.prefix < y.prefix)
89-
return true;
90-
else if (y.prefix < x.prefix)
91-
return false;
92-
return x.num < y.num;
93-
}
94-
95-
bool
96-
operator==(const section_num& x, const section_num& y)
97-
{
98-
if (x.prefix != y.prefix)
99-
return false;
100-
return x.num == y.num;
101-
}
102-
103-
bool
104-
operator!=(const section_num& x, const section_num& y)
105-
{
106-
return !(x == y);
107-
}
108-
10987
typedef std::string section_tag;
11088

11189
std::string

src/sections.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@
66
#include <cctype>
77
#include <utility>
88

9-
auto lwg::operator<(section_tag const & x, section_tag const & y) noexcept -> bool {
10-
return (x.prefix < y.prefix) ? true
11-
: (y.prefix < x.prefix) ? false
12-
: x.name < y.name;
13-
}
14-
15-
auto lwg::operator==(section_tag const & x, section_tag const & y) noexcept -> bool {
16-
return x.prefix == y.prefix && x.name == y.name;
17-
}
18-
19-
auto lwg::operator!=(section_tag const & x, section_tag const & y) noexcept -> bool {
20-
return !(x == y);
21-
}
22-
239
auto lwg::operator << (std::ostream& os, section_tag const & tag) -> std::ostream & {
2410
os << '[';
2511
if (!tag.prefix.empty()) { os << tag.prefix << "::"; }
@@ -34,23 +20,6 @@ std::string lwg::as_string(section_tag const & x)
3420
: x.prefix + "::" + x.name;
3521
}
3622

37-
auto lwg::operator < (section_num const & x, section_num const & y) noexcept -> bool {
38-
// prefixes are unique, so there should be no need for a tiebreak.
39-
return (x.prefix < y.prefix) ? true
40-
: (y.prefix < x.prefix) ? false
41-
: x.num < y.num;
42-
}
43-
44-
auto lwg::operator == (section_num const & x, section_num const & y) noexcept -> bool {
45-
return (x.prefix != y.prefix)
46-
? false
47-
: x.num == y.num;
48-
}
49-
50-
auto lwg::operator != (section_num const & x, section_num const & y) noexcept -> bool {
51-
return !(x == y);
52-
}
53-
5423
auto lwg::operator >> (std::istream& is, section_num& sn) -> std::istream & {
5524
sn.prefix.clear();
5625
sn.num.clear();

src/sections.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,22 @@ struct section_tag
1313
{
1414
std::string prefix; // example: fund.ts.v2
1515
std::string name; // example: meta.logical
16+
auto operator<=>(const section_tag&) const = default;
1617
};
1718

1819
struct section_num {
1920
std::string prefix; // example: fund.ts.v2
2021
std::vector<int> num; // sequence of numbers corresponding to section number
2122
// in relevant doc, e.g,, 17.5.2.1.4.2
23+
auto operator<=>(const section_num&) const = default;
2224
};
2325

2426
using section_map = std::map<section_tag, section_num>;
2527

26-
auto operator < (section_tag const & x, section_tag const & y) noexcept -> bool;
27-
auto operator == (section_tag const & x, section_tag const & y) noexcept -> bool;
28-
auto operator != (section_tag const & x, section_tag const & y) noexcept -> bool;
2928
auto operator << (std::ostream & os,
3029
section_tag const & tag) -> std::ostream &; // with square brackets
3130
std::string as_string(section_tag const & x); // without square brackets
3231

33-
auto operator < (section_num const & x, section_num const & y) noexcept -> bool;
34-
// section 'x' sorts before section 'y' if its 'prefix' field lexicographically
35-
// precedes that of 'y', and its 'nun' field lexicographically precedes that
36-
// of 'y' if the prefix fields are equivalent.
37-
38-
auto operator == (section_num const & x, section_num const & y) noexcept -> bool;
39-
auto operator != (section_num const & x, section_num const & y) noexcept -> bool;
40-
// Two 'section_num' objects compare equal if their 'prefix' and 'num' both
41-
// compare equal.
42-
4332
auto operator >> (std::istream & is, section_num & sn) -> std::istream &;
4433
auto operator << (std::ostream & os, section_num const & sn) -> std::ostream &;
4534

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy