Skip to content

Commit

Permalink
Merge branch 'topic/neverlord/obsolete-operators-header'
Browse files Browse the repository at this point in the history
* topic/neverlord/obsolete-operators-header:
  Remove obsolete operators.hh utility
  • Loading branch information
ckreibich committed Oct 19, 2024
2 parents 44cf64b + 475e0b9 commit 2a6e620
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 153 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.8.0-dev.133 | 2024-10-18 17:42:01 -0700

* Remove obsolete operators.hh utility (Dominik Charousset)

2.8.0-dev.131 | 2024-10-18 16:57:55 -0700

* Integrate review feedback (Dominik Charousset)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.8.0-dev.131
2.8.0-dev.133
1 change: 0 additions & 1 deletion bindings/python/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "broker/convert.hh"
#include "broker/data.hh"
#include "broker/detail/assert.hh"
#include "broker/detail/operators.hh"

namespace py = pybind11;
using namespace pybind11::literals;
Expand Down
6 changes: 6 additions & 0 deletions libbroker/broker/detail/comparable.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ namespace broker::detail {
/// Barton–Nackman trick implementation.
template <class Derived, class T = Derived>
class comparable {
public:
friend Derived;

friend bool operator==(const Derived& lhs, const T& rhs) noexcept {
return lhs.compare(rhs) == 0;
}
Expand Down Expand Up @@ -52,6 +55,9 @@ class comparable {
friend bool operator>=(const T& lhs, const Derived& rhs) noexcept {
return rhs <= lhs;
}

private:
comparable() = default;
};

template <class Derived>
Expand Down
31 changes: 0 additions & 31 deletions libbroker/broker/detail/operators.hh

This file was deleted.

58 changes: 15 additions & 43 deletions libbroker/broker/enum_value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <string>
#include <string_view>

#include "broker/detail/operators.hh"
#include "broker/detail/comparable.hh"

namespace broker {

/// Stores the name of an enum value. The receiver is responsible for knowing
/// how to map the name to the actual value if it needs that information.
struct enum_value : detail::totally_ordered<enum_value> {
struct enum_value : detail::comparable<enum_value> {
/// Default construct empty enum value name.
enum_value() = default;

Expand All @@ -21,17 +21,11 @@ struct enum_value : detail::totally_ordered<enum_value> {
}

std::string name;
};

/// @relates enum_value
inline bool operator==(const enum_value& lhs, const enum_value& rhs) {
return lhs.name == rhs.name;
}

/// @relates enum_value
inline bool operator<(const enum_value& lhs, const enum_value& rhs) {
return lhs.name < rhs.name;
}
inline auto compare(const enum_value& other) const {
return name.compare(other.name);
}
};

/// @relates enum_value
template <class Inspector>
Expand All @@ -45,8 +39,8 @@ inline void convert(const enum_value& e, std::string& str) {
}

/// Like enum_value, but wraps a value of type `std::string_view` instead.
class enum_value_view : detail::totally_ordered<enum_value_view>,
detail::totally_ordered<enum_value_view, enum_value> {
class enum_value_view : detail::comparable<enum_value_view>,
detail::comparable<enum_value_view, enum_value> {
public:
/// Default construct empty enum value name.
enum_value_view() = default;
Expand All @@ -57,37 +51,15 @@ public:
}

std::string_view name;
};

/// @relates enum_value
inline bool operator==(const enum_value_view& lhs, const enum_value_view& rhs) {
return lhs.name == rhs.name;
}

/// @relates enum_value_view
inline bool operator<(const enum_value_view& lhs, const enum_value_view& rhs) {
return lhs.name < rhs.name;
}

/// @relates enum_value
inline bool operator==(const enum_value_view& lhs, const enum_value& rhs) {
return lhs.name == rhs.name;
}

/// @relates enum_value_view
inline bool operator<(const enum_value_view& lhs, const enum_value& rhs) {
return lhs.name < rhs.name;
}

/// @relates enum_value
inline bool operator==(const enum_value& lhs, const enum_value_view& rhs) {
return lhs.name == rhs.name;
}
inline auto compare(const enum_value& other) const {
return name.compare(other.name);
}

/// @relates enum_value_view
inline bool operator<(const enum_value& lhs, const enum_value_view& rhs) {
return lhs.name < rhs.name;
}
inline auto compare(const enum_value_view& other) const {
return name.compare(other.name);
}
};

} // namespace broker

Expand Down
12 changes: 6 additions & 6 deletions libbroker/broker/network_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ network_info::network_info(std::string addr, uint16_t port,
timeout::seconds retry)
: address{std::move(addr)}, port{port}, retry{retry} {}

bool operator==(const network_info& x, const network_info& y) {
return x.address == y.address && x.port == y.port;
}

bool operator<(const network_info& x, const network_info& y) {
return std::tie(x.address, x.port) < std::tie(y.address, y.port);
int network_info::compare(const network_info& other) const {
auto res = address.compare(other.address);
if (res == 0) {
return static_cast<int>(port) - static_cast<int>(other.port);
}
return res;
}

std::string to_string(const network_info& x) {
Expand Down
12 changes: 4 additions & 8 deletions libbroker/broker/network_info.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#include <optional>
#include <string>

#include "broker/detail/operators.hh"
#include "broker/detail/comparable.hh"
#include "broker/timeout.hh"

namespace broker {

/// Represents an IP address and TCP port combination.
struct network_info : detail::totally_ordered<network_info> {
struct network_info : detail::comparable<network_info> {
network_info() = default;
network_info(std::string addr, uint16_t port,
timeout::seconds retry = timeout::seconds());
Expand All @@ -21,13 +21,9 @@ struct network_info : detail::totally_ordered<network_info> {
bool has_retry_time() const noexcept {
return retry.count() != 0;
}
};

/// @relates network_info
bool operator==(const network_info& x, const network_info& y);

/// @relates network_info
bool operator<(const network_info& x, const network_info& y);
int compare(const network_info& other) const;
};

/// @relates network_info
template <class Inspector>
Expand Down
16 changes: 8 additions & 8 deletions libbroker/broker/port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ port::port() : num_{0}, proto_{protocol::unknown} {}

port::port(number_type n, protocol p) : num_{n}, proto_{p} {}

int port::compare(const port& other) const {
auto res = static_cast<int>(num_) - static_cast<int>(other.num_);
if (res == 0) {
return static_cast<int>(proto_) - static_cast<int>(other.proto_);
}
return res;
}

port::number_type port::number() const {
return num_;
}
Expand All @@ -23,14 +31,6 @@ port::protocol port::type() const {
return proto_;
}

bool operator==(const port& lhs, const port& rhs) {
return lhs.proto_ == rhs.proto_ && lhs.num_ == rhs.num_;
}

bool operator<(const port& lhs, const port& rhs) {
return std::tie(lhs.num_, lhs.proto_) < std::tie(rhs.num_, rhs.proto_);
}

void convert(const port& p, std::string& str) {
str = std::to_string(p.number());
str += '/';
Expand Down
15 changes: 4 additions & 11 deletions libbroker/broker/port.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstdint>
#include <string>

#include "broker/detail/operators.hh"
#include "broker/detail/comparable.hh"
#include "broker/fwd.hh"

namespace broker {
Expand All @@ -15,7 +15,7 @@ void convert(const port& p, std::string& str);
bool convert(const std::string& str, port& p);

/// A transport-layer port.
class port : detail::totally_ordered<port> {
class port : detail::comparable<port> {
public:
using number_type = uint16_t;

Expand All @@ -32,6 +32,8 @@ public:
/// Construct a port from number/protocol.
port(number_type num, protocol p);

int compare(const port& other) const;

/// @return The port number.
number_type number() const;

Expand All @@ -40,9 +42,6 @@ public:

size_t hash() const;

friend bool operator==(const port& lhs, const port& rhs);
friend bool operator<(const port& lhs, const port& rhs);

template <class Inspector>
friend bool inspect(Inspector& f, port& x) {
if (f.has_human_readable_format()) {
Expand Down Expand Up @@ -78,12 +77,6 @@ bool inspect(Inspector& f, port::protocol& x) {
return f.apply(get, set);
}

/// @relates port
bool operator==(const port& lhs, const port& rhs);

/// @relates port
bool operator<(const port& lhs, const port& rhs);

} // namespace broker

namespace std {
Expand Down
17 changes: 13 additions & 4 deletions libbroker/broker/status.hh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "broker/convert.hh"
#include "broker/detail/operators.hh"
#include "broker/detail/type_traits.hh"
#include "broker/endpoint_info.hh"
#include "broker/error.hh"
Expand Down Expand Up @@ -100,9 +99,7 @@ template <class Inspector>
bool inspect(Inspector& f, status& x);

/// Diagnostic status information.
class status : detail::equality_comparable<status, status>,
detail::equality_comparable<status, sc>,
detail::equality_comparable<sc, status> {
class status {
public:
template <sc S>
static status make(endpoint_info ei, std::string msg) {
Expand Down Expand Up @@ -193,6 +190,18 @@ private:
std::string message_;
};

inline bool operator!=(const status& lhs, const status& rhs) {
return !(lhs == rhs);
}

inline bool operator!=(const status& lhs, sc rhs) {
return !(lhs == rhs);
}

inline bool operator!=(sc lhs, const status& rhs) {
return !(lhs == rhs);
}

/// @relates status
std::string to_string(const status& x);

Expand Down
16 changes: 8 additions & 8 deletions libbroker/broker/subnet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ subnet::subnet(const address& addr, uint8_t length) noexcept
len_ = 0;
}

int subnet::compare(const subnet& other) const {
auto res = net_.compare(other.net_);
if (res == 0) {
return static_cast<int>(len_) - static_cast<int>(other.len_);
}
return res;
}

bool subnet::init() {
if (net_.is_v4()) {
if (len_ > 32)
Expand Down Expand Up @@ -51,14 +59,6 @@ size_t subnet::hash() const {
return caf::hash::fnv<size_t>::compute(net_, len_);
}

bool operator==(const subnet& lhs, const subnet& rhs) {
return lhs.len_ == rhs.len_ && lhs.net_ == rhs.net_;
}

bool operator<(const subnet& lhs, const subnet& rhs) {
return std::tie(lhs.net_, lhs.len_) < std::tie(rhs.net_, lhs.len_);
}

void convert(const subnet& sn, std::string& str) {
convert(sn.network(), str);
str += '/';
Expand Down
Loading

0 comments on commit 2a6e620

Please sign in to comment.