problem with custom predicate

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 27 08:59:06 PDT 2015


On Wednesday, 27 May 2015 at 15:30:28 UTC, Steven Schveighoffer 
wrote:
> On 5/27/15 9:11 AM, "Simon =?UTF-8?B?QsO8cmdlciI=?= 
> <simon.buerger at rwth-aachen.de>" wrote:
>> On Wednesday, 27 May 2015 at 14:58:39 UTC, drug wrote:
>>
>>> Do you want to dynamically change priority?
>> Actually yes. In my actual code I am not using a RedBlackTree 
>> but my own
>> Container (a heap with the possibility to modify elements 
>> inside), which
>> is notified when prio changes so it can do a (local) 
>> reordering.
>
> It would be a very bad idea to change prio if the RBTree is 
> constructed already (and if this works).
>
>>> Why prio is outside of your predicate?
>> Well, how would I get it into the lambda? In C++ I would use a
>> comparision class, and the constructor of the container would 
>> take an
>> instance of that class. But D's RedBlackTree-constructor does 
>> not take
>> such a (run-time) argument. And I dont see a way to get prio 
>> into the
>> predicate, which is a template-argument.
>
> This is true, RedBlackTree does not take a functor as a 
> parameter to the constructor, it just uses an alias.
>
> This should work if your RedBlackTree is scoped inside a 
> function where the data exists. But at the time of declaration 
> inside the class, the instance of prio doesn't exist, so you 
> can't alias it.
>
> It would be a good enhancement I think to add support for 
> function objects.
>
> -Steve

I thought unaryFun *does* work with all callables, including 
structs/classes with opCall?


More information about the Digitalmars-d-learn mailing list