filter!(not!(predicate))(someInputRange) does not compile

Jens Mueller jens.k.mueller at gmx.de
Thu Jan 20 10:47:11 PST 2011


Andrei Alexandrescu wrote:
> On 1/19/11 7:19 PM, Jens Mueller wrote:
> >Andrei Alexandrescu wrote:
> >>Place the call to not!alwaysTrue in a local function inside main:
> >>
> >>     bool alwaysFalse(uint a) { return not!alwaysTrue(a); }
> >
> >Thanks. Can you elaborate a bit please? I wonder why the alias won't
> >work.
> 
> I thought of it for a bit. It's a limitation of the compiler that's
> worth a bug report. The explanation is a bit involved. Let me start
> by remarking that if you prepend "static" to alwaysTrue, the alias
> works as expected:
> 
> static bool alwaysTrue(uint a) { return true; }
> alias not!(alwaysTrue) alwaysFalse;
> 
> Without "static", alwaysTrue has access to a hidden pointer to the
> stack frame of the function is in.

Yeah. That makes sense.
It has this hidden pointer to access variables from the function it is
defined in.

> In theory a template should be unable to manipulate alwaysTrue
> because of that frame pointer. But Walter has had this great idea of
> instantiating templates in the context of the function they're in,
> so they gain access to the frame pointer too. However, that
> instantiation mechanism still has a few limitations. I think the
> code above runs into one of them.

I see.
I can file a bug report if it is considered important and should not be
forgotten.

Jens


More information about the Digitalmars-d mailing list