RBTree delegates and types
Steven Schveighoffer
schveiguy at yahoo.com
Mon Mar 19 11:30:13 UTC 2018
On 3/19/18 5:16 AM, Viktor wrote:
>
> Hi Steve, thanks for replying!
>
> I've also noticed that RedBlackTree.opEquals() is like this from the
> initial pull request and was wondering if noone has been using a
> delegate and why...
typically, you don't need a delegate, but generally, you CAN use a
delegate as an alias "less" function. I don't see why it should be
restricted here.
But this is probably why nobody ever found it -- most people just use
the default lambda.
>
> On the second topic, I've tried that and it doesn't work. I have a
> minimal test program that shows the issue.
>
> https://run.dlang.io/is/WNF78H
Oh! I totally missed that comp is a member function (in your first
example). I thought it was passed in. Sorry for not taking a closer look.
Yes, you need a `this` pointer for it to work. However, we can do this
by encapsulating the return type with an auto function:
https://run.dlang.io/is/inSzaU
Sorry I didn't get this right away. Interesting chicken-and-egg problem,
but as usual, D delivers :)
-Steve
More information about the Digitalmars-d-learn
mailing list