Allow Explicit Pointer for Auto Declaration

Jacob via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 30 16:20:07 PDT 2016


On Friday, 30 September 2016 at 13:37:43 UTC, Meta wrote:
>
> This suggestion has come up before but Andrei is against it.
>
> https://github.com/dlang/dmd/pull/3615
>
> It brings a tear to my eye.

Ah that's a shame, would like to reopen that conversation. Is 
there any way to ping him on the forums. I can see his case for 
not wanting "[$]" arrays, but I feel it's a different case for 
pointers.


Andralex on github:
> Complicates the language without a corresponding increase in 
> power

I'd say it increases readability and maintainability, that may 
not be an increase in "power" (what does that even mean) but I'd 
argue maintainability and readability are more important than 
"power". When you see "auto" you can't infer any information 
about it making it harder to read code. Adding some extra 
information to it can make it more readable at a glance.

> Small obscure feature of dubious usefulness that creates a 
> precedent for other small obscure features of increasingly 
> dubious usefulness

This functionality already exists in function form as seen below. 
So the foot is already in the door, it's a matter adding the 
functionality to auto declarations, for completeness and such ;).

> How about accepting stuff like that in function parameters, 
> etc? It's easy to argue that on grounds of completeness, now 
> that there's a foot in the door.

Ref as well. The functionality of reference is almost exactly a 
partial type specification. As in C++ a reference is denoted by 
"&", when you look at the implementaiton in C++ they are almost 
exactly the same.

for(auto* v : args);
for(auto& v : args);

So the functionality already exists as a reference as well. It 
exists in a function parameter as well as in a foreach statement. 
Basically everywhere that you made the argument against the 
feature, as it could extend to those areas as well. The only 
place "ref" doesn't exist in D is when specifying a variable. 
Otherwise it's almost exactly the same feature.



     import std.stdio;

     void test(T)(T* t) // functionality already exists in 
function form
     {
         writeln(T.stringof);
     }

     void main()
     {
         int* p;

         test(p);
         // test(10); // error won't compile this

         foreach(ref v ; 0 .. 10) // basically equivalent to C++: 
for(auto& v : arr)
         {
         }
     }



More information about the Digitalmars-d mailing list