#3672·SFML

Use member operators instead of independent operators

Author: mikomikotaishiCreated Feb 17, 2026Updated Apr 22, 2026
Labelsfeature

Prerequisite Checklist

Describe your feature request here

In my C++ modules proposal (#3467) I seem to run into a problem with ADL and finding the operator== for sf::IpAddress. It seems that it fails to correctly find operator==(IpAddress, IpAddress) (when I use import sfml;), but not if using #include <SFML/Network/IpAddress.hpp>. (It is, however, also solved by adding those operators into global scope with using.)

While I understand C++ modules are not an officially supported feature yet, the discussion of moving SFML 4 to C++20 (#3143) makes discussing modules a worthwhile matter, which is why I think proposing moving the independent operators into becoming member operators should be given consideration.

Use Cases

This allows us to avoid using ADL and just instead use a member operator, and avoids the need for friend operator. For classes like sf::IpAddress, there isn't much need for the left-hand side since they are all just comparing IpAddresses. From a maintenance point of view, it would be an improvement for encapsulation as it's clearer that the class "owns" the operator.

API Example

Instead:

cpp
class IpAddress {
public:
    // ...

    [[nodiscard]]
    SFML_NETWORK_API bool operator==(IpAddress other);

    [[nodiscard]]
    SFML_NETWORK_API bool operator!=(IpAddress other);

    // ...
};