[Bro-Dev] [Bro-Commits] [git/bro] topic/v6-addr: Interface draft for new IP address wrapper class. (0868317)
Matthias Vallentin
vallentin at icir.org
Tue Jan 24 11:47:58 PST 2012
> Oops, that are typos. That's supposed to look like this instead:
>
> enum Family { IPv4, IPv6 };
> enum ByteOrder { Host, Network };
>
> Does that make more sense? :)
Yes :-).
> I have this old rule of thumb in my head to define binary operators
> outside of classes. What was the use case where that's needed?
I think you're actually right: binary operators outside of classes
improve implicit type conversion. Say you implement for some reason
operator/ for IP addresses and have an instance ip of your class, then
the expression
192.168.0.1 / ip
only works operator/ is implemented as non-member function (in the same
namespace as the IP address class). Or put differently, the member
implementation of a binary operator forces the LHS of an expression to
of that class type, which limits the operator symmetry:
addr("192.168.0.1) / 192.168.0.1
will work, but
192.168.0.1 / addr("192.168.0.1)
will not.
Matthias
More information about the bro-dev
mailing list