Problem Instantiating a BinaryHeap with a Comparison Function the needs this
Gary Willoughby via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 19 04:59:32 PST 2015
On Thursday, 19 February 2015 at 11:56:19 UTC, Nordlöw wrote:
> I can understand how to correctly define an instance of
> BinaryHeap in my class DijkstraWalker at
>
> https://github.com/nordlow/justd/blob/master/knet/traversal.d#L264
>
> because the comparsion function can't ge access to the class
> member distMap
>
> I get the error
>
> need 'this' for 'distMap' of type 'Tuple!(double,
> Ref!(Node))[Ref!(Node)]'
>
> What to do?
I don't know if the lambda form can access the outer scope. Try
different forms for the comparer:
auto comparer = delegate (a, b)
{
return this.distMap[a][0] < this.distMap[b][0];
}
BinaryHeap!(Nds, comparer) pendingNds;
or
BinaryHeap!(Nds, "this.distMap[a][0] < this.distMap[b][0]")
pendingNds;
Caveat: this is off the top of my head and no way even tested or
read the docs. :)
More information about the Digitalmars-d-learn
mailing list