Two functions with different args. Taking address of the one
Виталий Фадеев
vital.fadeev at gmail.com
Thu Mar 11 12:56:34 UTC 2021
On Thursday, 11 March 2021 at 12:48:13 UTC, Paul Backus wrote:
> On Thursday, 11 March 2021 at 12:26:07 UTC, Виталий Фадеев
> wrote:
>> Have:
>> void process( ref MouseKeyEvent event )
>> {
>> ...
>> }
>>
>> void process( ref MouseMoveEvent event )
>> {
>> ...
>> }
>>
>> Want:
>> _processMouseKey = &process; // <-- not works
>> _processMouseMove = &process; // <-- not works
>>
>> What is correct way to get address of function with specific
>> argument ?
>
> You can use __traits(getOverloads, process) plus some
> metaprogramming to get the address of a specific overload. But
> IMO the easiest way is to use lambdas:
>
> __processMouseKey = (ref MouseKeyEvent event) {
> process(event); };
> __processMouseMove = (ref MouseMoveEvent event) {
> process(event); };
This will generate lambda:
__processMouseKey = (ref MouseKeyEvent event) { process(event);
};
two calls:
call labnda;
call process;
What right way to call function directly with selecting one of
two ?
More information about the Digitalmars-d-learn
mailing list