std.socket.Address not allowed in tuples

Neia Neutuladh neia at ikeran.org
Wed Jan 23 16:30:33 UTC 2019


On Wed, 23 Jan 2019 15:56:15 +0000, Steven O wrote:
> Why am I not allowed to put Address types in tuples?

As always, it helps a lot to post the error message the compiler gave you. 
The message is:

/usr/include/dmd/phobos/std/functional.d-mixin-215(215): Error: template 
std.typecons.Tuple!(Address, int).Tuple.opCmp cannot deduce function from 
argument types !()(Tuple!(Address, int)) inout, candidates are:
/usr/include/dmd/phobos/std/typecons.d(806):        std.typecons.Tuple!
(Address, int).Tuple.opCmp(R)(R rhs) if (areCompatibleTuples!
(typeof(this), R, "<"))
/usr/include/dmd/phobos/std/typecons.d(820):        std.typecons.Tuple!
(Address, int).Tuple.opCmp(R)(R rhs) if (areCompatibleTuples!
(typeof(this), R, "<"))
/usr/include/dmd/phobos/std/container/rbtree.d(866): Error: template 
instance `std.functional.binaryFun!("a < b", "a", "b").binaryFun!
(inout(Tuple!(Address, int)), Tuple!(Address, int))` error instantiating
scratch.d(13):        instantiated from here: RedBlackTree!(Tuple!
(Address, int), "a < b", false)

The last line says that the error came when trying to instantiate the 
RedBlackTree template. At that point, Tuple was instantiated. There is no 
issue putting an address in a Tuple.

The issue is that Address doesn't have a comparison operator defined, so 
the resulting tuple type can't be compared with the standard operators. 
You need to define your own function for comparing the tuples in question 
and pass that to RedBlackTree.


More information about the Digitalmars-d-learn mailing list