Three Unlikely Successful Features of D

Walter Bright newshound2 at digitalmars.com
Tue Mar 20 19:47:15 PDT 2012


On 3/20/2012 4:39 PM, H. S. Teoh wrote:
> On Tue, Mar 20, 2012 at 06:58:31PM -0400, Nick Sabalausky wrote:
>> - Type inference
>
> Yeah I forgot about this one. Being able to write:
>
> 	auto veryLongNamedObject = new VeryLongNamedClass(veryLongArguments);
>
> is a big boon over C++ or Java's stuttering verbosity:
>
> 	VeryLongNamedClass veryLongNamedObject = new VeryLongNamedClass(veryLongArguments);
>
> Plus, it's immensely useful when dealing with Range templates... can you
> imagine the horrifically long typenames you'd have to type you have to
> explicitly specify the type of a long chain of functional expressions
> involving 15+ std.algorithm and std.range templates?

Andrei discovered an amazing use of auto. It enables you to create variables 
with voldemort types "that may not be named".

For example:

   auto foo()
   {
     struct S { ... }
     S s;
     return s;
   }

   auto x = foo();

And now x is an instance of a voldemort type! It's completely encapsulated.


More information about the Digitalmars-d mailing list