DMD 0.177 release

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Wed Dec 20 04:56:43 PST 2006


Reiner Pope wrote:
> Andrei Alexandrescu (See Website for Email) wrote:
>> Lionello Lunesu wrote:
>>> I'd like "auto" to appear on more places as it will make templates 
>>> more accessible than ever before. For example, this notation has been 
>>> suggested a couple of times:
>>>
>>> void func(auto x) { }
> 
>> So in the end the "auto" suggestion is a mere shortcut for:
>>
>> void func(S T)(S T x) { }
>>
>> with the difference that the storage and type entities are clearly 
>> bound to symbols, style that's more in the spirit of D.
> 
> The motivation I see for such a shortcut is that this template pattern 
> is used so often that it is worth simplifying. Furthermore, the 
> variables S and T are often just dummy variables to satisfy the 
> requirements of the template; you don't even need these symbols, and 
> they fill the namespace.

I'm definitely one for shortcuts, but let's not forget that at the 
moment we lack the feature that the shortcut is supposed to simplify. At 
this moment, "auto" helps solving the storage class parameterization 
issue as much as a great color for the seat covers helps designing an 
economic automobile.

Let me illustrate further why ident is important and what solution we 
should have for it. Consider C's response to ident:

#define IDENT(e) (e)

Now, you can use IDENT with many C expressions (except those that have 
top-level commas), so we should be glad. Or should we? A true solution 
is to intercept the type of the expression and intelligently pass it as 
the return type of the function. In the general case, that means the 
language offers total control to the programmer of the types tossed 
around by a program. Instead, the C solution cheats its way around in 
that it has absolutely no grip on the expression type; it just gives the 
illusion that a function call is going on.

Similarly, let's say that a group of revolutionaries convinces Walter 
(as I understand happened in case of using "length" and "$" inside slice 
expressions, which is a shame and an absolute disaster that must be 
undone at all costs) to implement "auto", therefore leading to the 
following implementation of ident:

auto ident(auto x) {
   return x;
}

In the euphoria of the celebration, it will be initially forgotten that 
we have the shortcut without the feature, for the feature means having 
access to the exact type and storage of x, not finding a way to 
comfortably specify a deduction process.


Andrei



More information about the Digitalmars-d-announce mailing list