Thread overview
generic function instance without call
Apr 27, 2022
vit
Apr 27, 2022
vit
Apr 27, 2022
user1234
Apr 27, 2022
vit
Apr 27, 2022
user1234
April 27, 2022

Hi, is it possible to get address of generic function instance for specified arguments without calling the function?

Example:


auto foo(alias fn, Args...)(auto ref Args args){
    ///return function/delegate type of `fn` for arguments `args`
}

void main(){

    long x;

    auto fn = foo!((a, b) => true)(new int(42), x);

    static assert(is(typeof(fn) == bool function(int*, scope ref long)@safe pure nothrow @nogc ));
}

April 27, 2022

Fix:

auto fn = foo!((a, ref b) => true)(new int(42), x);
April 27, 2022

On Wednesday, 27 April 2022 at 15:23:26 UTC, vit wrote:

>

Hi, is it possible to get address of generic function instance for specified arguments without calling the function?

Example:


auto foo(alias fn, Args...)(auto ref Args args){
    ///return function/delegate type of `fn` for arguments `args`
}

void main(){

    long x;

    auto fn = foo!((a, b) => true)(new int(42), x);

    static assert(is(typeof(fn) == bool function(int*, scope ref long)@safe pure nothrow @nogc ));
}

yeah sure; declare an alias that (fully) specialize the generic func and take the address using the alias Identifier.

April 27, 2022

On Wednesday, 27 April 2022 at 16:03:32 UTC, user1234 wrote:

>

On Wednesday, 27 April 2022 at 15:23:26 UTC, vit wrote:

>

Hi, is it possible to get address of generic function instance for specified arguments without calling the function?

Example:


auto foo(alias fn, Args...)(auto ref Args args){
    ///return function/delegate type of `fn` for arguments `args`
}

void main(){

    long x;

    auto fn = foo!((a, b) => true)(new int(42), x);

    static assert(is(typeof(fn) == bool function(int*, scope ref long)@safe pure nothrow @nogc ));
}

yeah sure; declare an alias that (fully) specialize the generic func and take the address using the alias Identifier.

This work for types but not for attributes like scope, return and auto ref.

April 27, 2022

On Wednesday, 27 April 2022 at 17:22:14 UTC, vit wrote:

>

This work for types but not for attributes like scope, return and auto ref.

Oh sorry... auto ref... I totally forgot this old bug