Home:ALL Converter>Comparing two objects - strict weak

Comparing two objects - strict weak

Ask Time:2015-01-24T21:20:05         Author:Yotam

Json Formatter

I have a problem comparing objects of the following class: (Only the fields are relevant)

class Rule{

private:
    string _src_IP,
        _src_port,
        _dest_IP,
        _dest_port,
        _protocol; };

_src_IP and _dst_IP can contain an IP address ("0.0.0.0"-"255.255.255.255") or "any".
_src_Port and _dst_Port can contain a port number ("0" - "65535") or "any".
_protocol can contain "TCP", "UDP", or "any".

The difficulty is creating a comparison (operator< and operator>) which will satisfy the standard mathematical definition of a strict weak ordering.

If someone can think of something, that will be very helpful.

Author:Yotam,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28125871/comparing-two-objects-strict-weak
yy