auto keyword

Michael michaelhusmann at gmail.com
Thu Jan 30 09:37:40 UTC 2020


auto is surely a nice feature. Nonetheless I'd prefer to use 
explicit types. So when reading a code and I see the auto keyword 
I also have to find out what kind of type is meant.

I have a line of code that looks like this:
auto elements = buf.to!string.strip.split(" ").filter!(a => a != 
"");

That line strips white space from buf, splits it, removes empty 
elements and returns an array of strings. At least I thought so.

Indeed elements can be treated as a string slice, but if i 
replace auto by string[] the compiler complains:
Error: cannot implicitly convert expression 
filter(split(strip(to(buf)), " ")) of type 
FilterResult!(__lambda1, string[]) to string[]

In order to use an explicit type I wonder what kind of type I 
might use instead of auto?


More information about the Digitalmars-d-learn mailing list