Consider the following pattern:
mixin template test(void function() callback) { static this() { callback(); } }
It works:
mixin test!(&sort_arr); void sort_arr() { arr.sort; }
However, this does not work:
mixin test!({ arr.sort; });
DMD gives the following error:
Error: safe function 'main.__lambda6' cannot call system function '_adSort' Error: @nogc function 'main.__lambda6' cannot call non-@nogc function '_adSort'
It seems to me that the lambda version is considered safe @nogc , and the explicit sort_arr not.
How can I overcome this and pass an anonymous lambda to this template?
Edit: bug report filed as recommended in the accepted answer: https://issues.dlang.org/show_bug.cgi?id=13481
source share