problem with custom predicate
Timon Gehr via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed May 27 09:14:45 PDT 2015
On 05/27/2015 05:30 PM, 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
>
Also, apart from missing implementation, there is no good reason why the
code given should not work, is there? I think nested template
instantiation should work in all scopes. (Of course, there is the issue
that nested structs are somewhat arbitrarily not given a context pointer
when declared within a class/struct, so this might be a little
inconsistent in case it also works for structs, no question for classes
though: just instantiate as nested class.)
More information about the Digitalmars-d-learn
mailing list