On Friday, 16 November 2018 at 12:12:12 UTC, Alex wrote:
=====================================================
This code compiles as long as `lazy` is commented out. But I'd like to have both lazy parameter and @nogc inferrence for `library_func` so that user is not locked to code @nogc or not.

Aha, aha... Interesting!
I had a similar problem with passing a delegate. And it was solved:
https://forum.dlang.org/thread/erznqknpyxzxqivaw...@forum.dlang.org

For your problem, there is a bug report:
https://forum.dlang.org/post/wedwfooqdxbwxttpm...@forum.dlang.org
https://issues.dlang.org/show_bug.cgi?id=12664
https://issues.dlang.org/show_bug.cgi?id=12647

Thanks for these links.
And yes, I have workaround with handmade delegate. It compiles and it is lazy, but also ugly.

import std.traits;

T library_func(T)(/*not lazy*/ T i) if (!isCallable!T)
{
    return i;
}
ReturnType!T library_func(T)(/*lazy*/ T i) if (isCallable!T)
{
    return i();
}
void user_function_nogc() @nogc
{
    int x = 1;
    library_func(x+1);
}
void user_function_gc()
{
    library_func(()=>[1]);
}
void main()
{
}

Reply via email to