foreach syntax

Jonathan M Davis jmdavisProg at gmx.com
Fri Jun 29 12:58:59 PDT 2012


On Friday, June 29, 2012 21:51:20 Namespace wrote:
> But there is no overhead or something else _if_ i put the type,
> or?

No. It's like auto. The type is inferred. It's all statically typed and 
strongly typed. It's not like it figures out the type at runtime or anything 
like that. It's all done at compile time. It's just like C++11's auto. It 
makes refactoring code a lot easier, and it makes generic code a _lot_ easier 
to write. Without auto, std.algorithm would pretty much be impossible (you 
_could_ do it, but it would be so disgusting that no one would want to use it, 
because all of those compound range types get truly hideous if you actually 
look at the types themselves - voldemort types have reduced that problem, but 
they'd be impossible without auto anyway). It's up to you whether you want to 
put types explicitly or use let them be inferred with auto or in foreach 
loops, but it's more or less common practice at this point to use type 
inferrence very heavily and to avoid using types explicitly except when you 
need to.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list