Skip to content

Commit 7752605

Browse files
authored
[cxx20] Use defaulted comparison operators (#4502)
This replaces a few manually-implemented comparison operators with the defaults. I guess these got missed in the big C++20 PR.
2 parents 47edaa2 + 059b0c7 commit 7752605

File tree

6 files changed

+11
-90
lines changed

6 files changed

+11
-90
lines changed

include/multipass/cloud_init_iso.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,12 @@ class CloudInitIso
4242
void write_to(const std::filesystem::path& path);
4343
void read_from(const std::filesystem::path& path);
4444

45-
friend bool operator==(const CloudInitIso& lhs, const CloudInitIso& rhs)
46-
{
47-
return lhs.files == rhs.files;
48-
}
45+
friend bool operator==(const CloudInitIso& lhs, const CloudInitIso& rhs) = default;
4946

5047
private:
5148
struct FileEntry
5249
{
53-
friend bool operator==(const FileEntry& lhs, const FileEntry& rhs)
54-
{
55-
return std::tie(lhs.name, lhs.data) == std::tie(rhs.name, rhs.data);
56-
}
50+
friend bool operator==(const FileEntry& lhs, const FileEntry& rhs) = default;
5751

5852
std::string name;
5953
std::string data;

include/multipass/memory_size.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ namespace multipass
2424
class MemorySize
2525
{
2626
public:
27-
friend bool operator==(const MemorySize& a, const MemorySize& b) noexcept;
28-
friend bool operator!=(const MemorySize& a, const MemorySize& b) noexcept;
29-
friend bool operator<(const MemorySize& a, const MemorySize& b) noexcept;
30-
friend bool operator>(const MemorySize& a, const MemorySize& b) noexcept;
31-
friend bool operator<=(const MemorySize& a, const MemorySize& b) noexcept;
32-
friend bool operator>=(const MemorySize& a, const MemorySize& b) noexcept;
27+
friend inline bool operator==(const MemorySize& a, const MemorySize& b) noexcept = default;
28+
friend inline auto operator<=>(const MemorySize& a, const MemorySize& b) noexcept = default;
3329

3430
MemorySize() noexcept;
3531
explicit MemorySize(const std::string& val);
@@ -49,11 +45,4 @@ class MemorySize
4945

5046
long long in_bytes(const std::string& mem_value);
5147

52-
bool operator==(const MemorySize& a, const MemorySize& b) noexcept;
53-
bool operator!=(const MemorySize& a, const MemorySize& b) noexcept;
54-
bool operator<(const MemorySize& a, const MemorySize& b) noexcept;
55-
bool operator>(const MemorySize& a, const MemorySize& b) noexcept;
56-
bool operator<=(const MemorySize& a, const MemorySize& b) noexcept;
57-
bool operator>=(const MemorySize& a, const MemorySize& b) noexcept;
58-
5948
} // namespace multipass

include/multipass/network_interface.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#pragma once
1919

2020
#include <string>
21-
#include <tuple>
2221

2322
namespace multipass
2423
{
@@ -27,10 +26,8 @@ struct NetworkInterface
2726
std::string id;
2827
std::string mac_address;
2928
bool auto_mode;
29+
30+
friend inline bool operator==(const NetworkInterface& a, const NetworkInterface& b) = default;
3031
};
3132

32-
inline bool operator==(const NetworkInterface& a, const NetworkInterface& b)
33-
{
34-
return std::tie(a.id, a.auto_mode, a.mac_address) == std::tie(b.id, b.auto_mode, b.mac_address);
35-
}
3633
} // namespace multipass

include/multipass/network_interface_info.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
#include <algorithm>
2323
#include <string>
24-
#include <tuple>
2524
#include <vector>
2625

2726
namespace multipass
@@ -39,12 +38,9 @@ struct NetworkInterfaceInfo
3938
std::string description;
4039
std::vector<std::string> links = {}; // default initializer allows aggregate init of the other 3
4140
bool needs_authorization = false; // idem
42-
};
4341

44-
inline bool operator==(const NetworkInterfaceInfo& a, const NetworkInterfaceInfo& b)
45-
{
46-
return std::tie(a.id, a.type, a.description, a.links, a.needs_authorization) ==
47-
std::tie(b.id, b.type, b.description, b.links, b.needs_authorization);
48-
}
42+
friend inline bool operator==(const NetworkInterfaceInfo& a,
43+
const NetworkInterfaceInfo& b) = default;
44+
};
4945

5046
} // namespace multipass

include/multipass/vm_image_info.h

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,7 @@ class VMImageInfo
3737
QString version;
3838
int64_t size;
3939
bool verify;
40-
};
4140

42-
inline bool operator==(const VMImageInfo& a, const VMImageInfo& b)
43-
{
44-
return std::tie(a.aliases,
45-
a.os,
46-
a.release,
47-
a.release_title,
48-
a.release_codename,
49-
a.supported,
50-
a.image_location,
51-
a.id,
52-
a.stream_location,
53-
a.version,
54-
a.size,
55-
a.verify) == std::tie(b.aliases,
56-
b.os,
57-
b.release,
58-
b.release_title,
59-
b.release_codename,
60-
b.supported,
61-
b.image_location,
62-
b.id,
63-
b.stream_location,
64-
b.version,
65-
b.size,
66-
b.verify);
67-
}
41+
friend inline bool operator==(const VMImageInfo& a, const VMImageInfo& b) = default;
42+
};
6843
} // namespace multipass

src/utils/memory_size.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -118,36 +118,6 @@ long long mp::MemorySize::in_gigabytes() const noexcept
118118
return bytes / gibi; // integer division to floor
119119
}
120120

121-
bool mp::operator==(const MemorySize& a, const MemorySize& b) noexcept
122-
{
123-
return a.bytes == b.bytes;
124-
}
125-
126-
bool mp::operator!=(const MemorySize& a, const MemorySize& b) noexcept
127-
{
128-
return a.bytes != b.bytes;
129-
}
130-
131-
bool mp::operator<(const MemorySize& a, const MemorySize& b) noexcept
132-
{
133-
return a.bytes < b.bytes;
134-
}
135-
136-
bool mp::operator>(const MemorySize& a, const MemorySize& b) noexcept
137-
{
138-
return a.bytes > b.bytes;
139-
}
140-
141-
bool mp::operator<=(const MemorySize& a, const MemorySize& b) noexcept
142-
{
143-
return a.bytes <= b.bytes;
144-
}
145-
146-
bool mp::operator>=(const MemorySize& a, const MemorySize& b) noexcept
147-
{
148-
return a.bytes >= b.bytes;
149-
}
150-
151121
std::string mp::MemorySize::human_readable(unsigned int precision, bool trim_zeros) const
152122
{
153123
const auto giga = std::pair{gibi, "GiB"};

0 commit comments

Comments
 (0)