MCPcopy Create free account
hub / github.com/andreasfertig/programming-with-cpp20 / Address

Class Address

06.16-customOrdering1/main.cpp:9–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include <string>
8
9struct Address {
10 std::string city;
11 std::string street;
12 uint32_t street_no;
13
14 auto operator<=>(const Address& rhs) const
15 {
16 // #A Sort city and street using their <=>
17 if(const auto& cmp = city <=> rhs.city; cmp != 0) {
18 return cmp;
19 } else if(const auto& scmp = street <=> rhs.street;
20 scmp != 0) {
21 return scmp;
22 }
23
24 // #B Next, sort street_no ascending
25 return rhs.street_no <=> street_no;
26 }
27
28 // #C The default should be good enough here
29 bool operator==(const Address&) const = default;
30};
31
32int main()
33{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected