Summary
A user storing endpoints as keys in an ordered container (std::map<endpoint, ...>) for session management needs endpoint to be ordered-comparable. Today boost::corosio::endpoint provides only operator== and operator!= (see include/boost/corosio/endpoint.hpp:200-219), so it cannot be used as a std::map/std::set key without a custom comparator.
Request
Add relational operators (operator<, operator<=, operator>, operator>=) to corosio::endpoint, providing a strict total ordering. A defaulted/explicit operator<=> would cover all of these in one shot.
Motivation
While refactoring some session-management code, we store an endpoint (currently asio::ip::tcp::endpoint) in a map and do lookups against it (new vs. existing endpoint message requests). Would it be possible to add operator<, operator<=, etc. to corosio::endpoint? You already have the equality operators. We can work around it if there's no plan to add these, but it was something noticed while working through this.
This also aids migration from Asio: asio::ip::tcp::endpoint already provides these relational operators, so code that uses endpoints as ordered keys ports over without introducing a custom comparator.
Notes / open questions
- Ordering semantics: equality currently keys on
(is_v4_, port_, address). The ordering should be consistent with operator== (equal endpoints compare neither < nor >). Need to decide the comparison key order (e.g. address family, then address, then port) and document it. Asio orders by address then port.
- Implementation: likely cleanest as a
friend operator<=> returning std::strong_ordering, keeping the existing operator==. Worth confirming the C++ standard baseline supports <=> across all supported toolchains; otherwise provide the four operators explicitly.
- Same consideration may apply to
local_endpoint, which also currently has only equality operators.
Summary
A user storing endpoints as keys in an ordered container (
std::map<endpoint, ...>) for session management needsendpointto be ordered-comparable. Todayboost::corosio::endpointprovides onlyoperator==andoperator!=(seeinclude/boost/corosio/endpoint.hpp:200-219), so it cannot be used as astd::map/std::setkey without a custom comparator.Request
Add relational operators (
operator<,operator<=,operator>,operator>=) tocorosio::endpoint, providing a strict total ordering. A defaulted/explicitoperator<=>would cover all of these in one shot.Motivation
This also aids migration from Asio:
asio::ip::tcp::endpointalready provides these relational operators, so code that uses endpoints as ordered keys ports over without introducing a custom comparator.Notes / open questions
(is_v4_, port_, address). The ordering should be consistent withoperator==(equal endpoints compare neither<nor>). Need to decide the comparison key order (e.g. address family, then address, then port) and document it. Asio orders by address then port.friendoperator<=>returningstd::strong_ordering, keeping the existingoperator==. Worth confirming the C++ standard baseline supports<=>across all supported toolchains; otherwise provide the four operators explicitly.local_endpoint, which also currently has only equality operators.