Skip to content

Add relational operators to corosio::endpoint for use as ordered map key #258

@sgerbino

Description

@sgerbino

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions