Attribute inference for auto functions?

Walter Bright newshound2 at digitalmars.com
Sat Apr 20 11:34:45 PDT 2013


On 4/20/2013 1:50 AM, Mehrdad wrote:
> On Saturday, 20 April 2013 at 06:25:09 UTC, Walter Bright wrote:
>> On 4/19/2013 11:12 PM, deadalnix wrote:
>>> But some time, you can't alias (in case of inference for instance) and so
>>> can't choose what attribute bind to.
>>
>> Example, please.
>
>
> Here you go:
>
> void foo(T)(extern(C) T function() function() f);
>
>
> Try making the extern(C) apply to each of:
> 1. the result of f()
> 2. the result of f()()
>
>
> without breaking foo()'s type inference.

What I've been trying to explain is that there's a difference between a storage 
class attribute and a type constructor. When pure, for example, is used as a 
storage class attribute, it applies to the declaration always. When pure is used 
as a type constructor, it applies to the type, always. There is no ambiguity 
about this, and no problem about choice.

For your example, for purity:

     void foo(T)(T function() pure function() pure f);

The only issue here is that extern(C) is not currently supported as a type 
constructor. If it were, the example would look like:

     void foo(T)(T function() extern(C) function() extern(C) f);

Again, there is no ambiguity.



More information about the Digitalmars-d mailing list