How to partially apply member functions?

ct via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 29 05:37:40 PDT 2017


On Thursday, 29 June 2017 at 12:31:58 UTC, ct wrote:
> I have something similar to the following:
>
> class Editor {
>   void OnNextPreviousMatch(bool is_forward, SearchEntry entry) {
> }
> }

I pressed send by mistake. Again, I have something similar to the 
following:

class Editor {
   void OnNextPreviousMatch(bool is_forward, SearchEntry entry) {
     // ...
   }
}

In another member function, I want to partially apply a delegate:

class Editor {
   void OnNextPreviousMatch(bool is_forward, SearchEntry entry) {
     // ...
   }

   void InstallHandlers() {
     entry_.addOnNextMatch(partial!(&this.OnNextPreviousMatch, 
true));
     entry_.addOnPreviousMatch(partial!(&this.OnNextPreviousMatch, 
false));
   }
}

I tried several things, but I keep getting compiler errors:

Error: value of 'this' is not known at compile time
/usr/include/dmd/phobos/std/functional.d(664,23): Error: need 
'this' for 'OnNextPreviousMatch' of type 'void(bool is_forward, 
SearchEntry entry)'


More information about the Digitalmars-d-learn mailing list