What is this strange alias syntax?

Steven Schveighoffer schveiguy at yahoo.com
Mon May 23 11:24:56 PDT 2011


On Mon, 23 May 2011 14:06:31 -0400, Timon Gehr <timon.gehr at gmx.ch> wrote:

> Steven Schveighoffer wrote:
>> On Mon, 23 May 2011 10:50:11 -0400, Andrej Mitrovic
>> <andrej.mitrovich at gmail.com> wrote:
>>
>>> Since &main can't be a template value argument, maybe he meant this use
>>> case:
>>>
>>> alias int func();
>>>
>>> void foo(alias T)()
>>> {
>>       static assert(is(typeof(&T) == int function())); // fixed
>>> }
>>>
>>> int main()
>>> {
>>>     foo!main;
>>>     return 0;
>>> }
>
> Oh, I am sorry. I did not realize that D does not allow overloading the  
> address-of
> operator. (C++ does, but D is quite restrictive, I have to get used to  
> that)
> Therefore, this solution works of course unambiguously.
>
> Well, you could kill alias R func(T); in that case, but still, it makes  
> the
> compiler more complicated. :)

I went to Don's thread to give you a good case of why it's worth it, and I  
realized that his example looks nothing like what yours does, and in fact,  
is disallowed in the latest compiler.  So we have been talking about two  
completely different problems.

The issue was for C-style function type declarations:

int x;
x(y); // declare a function type y which returns an x, but looks like a  
function call.

Here was the bug report:   
http://d.puremagic.com/issues/show_bug.cgi?id=4987

So although I think the alias function syntax is horrible, it's not nearly  
as bad as I thought.  I also still don't see much use for it, it seems  
much more straightforward to use function pointers as types instead.  I'd  
favor removing it, but I was wrong that it was already scheduled to be  
removed.

-Steve


More information about the Digitalmars-d-learn mailing list