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

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jan 20 11:44:20 PST 2011


On 1/20/11 12:47 PM, Jens Mueller wrote:
> 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

Yes please. Make it an enhancement as it would remove a limitation of an 
otherwise little explored feature. Thanks!

Andrei


More information about the Digitalmars-d mailing list