Accepting delegates/functions in templates
Ali Çehreli
acehreli at yahoo.com
Mon May 27 08:26:50 PDT 2013
On 05/27/2013 07:05 AM, "Luís Marques" <luismarques at gmail.com>" wrote:
> If I changed that example to use isSomeFunction it works correctly. But
> when I tried to use isSomeFunction in the proper context it fails to
> compile:
It is a red herring. The code fails to compile even without isSomeFunction.
import std.traits;
> class A
> {
> void foo(alias dg)()
> if(isSomeFunction!dg)
> {
> }
> }
>
> void main()
> {
> int x;
> A a = new A;
> a.foo!((int param) { x = 4;});
>
> // error: cannot use local '__lambda1' as parameter to
non-global
> template foo(alias dg)() if (isSomeFunction!(dg))
> }
>
> Can anyone help me understand this?
It is an unsolved technical issue about delegates' currently not having
sufficient number of context pointers:
http://d.puremagic.com/issues/show_bug.cgi?id=5710
Ali
More information about the Digitalmars-d-learn
mailing list