functors with template lambdas
Vlad Levenfeld via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri May 15 19:04:38 PDT 2015
I think this code should be allowed, but it isn't:
struct Functor (T)
{
T a;
auto ref fmap (alias f)()
{
return Functor (f(a));
}
}
auto ref identity (T)(auto ref T a)
{
return a;
}
void main()
{
Functor!int a;
static auto id (T)(T x)
{return x;}
a.fmap!identity; // ok
a.fmap!id; // ok
a.fmap!((int x) => x); // ok
a.fmap!(x => x); // Error: template instance fmap!((x) => x)
cannot use local '__lambda1' as parameter to non-global template
fmap(alias f)()
}
This seems like one of those things that doesn't work because of
some compiler implementation detail rather than a consequence of
the language rules but I'm not sure. Opinion?
More information about the Digitalmars-d-learn
mailing list