I don't like auto. (the auto-typing I mean)

Kevin Bealer Kevin_member at pathlink.com
Sat Mar 11 11:38:42 PST 2006


In article <duugks$2qo3$1 at digitaldaemon.com>, Ameer Armaly says...
>
..
>> someOtherFunction((float)someFunction());
>>
>> So why is this any different from:
>>
>> auto fork = someFunction();
>> someOtherFunction(fork);
>>
>> ?
>>
>Since it's obviously something we don't want, just because it exists doesn't 
>mean we should compound the problem by making it even more common.
>> /Oskar 

I disagree - there are times when I *do* want exactly that behavior.  Lets say I
have a group of PrintObject() methods that handle the different types I use in
my program.

Then I can do this:

void foo()
{
auto f = someFunction();
PrintObject(f);
}

My code will work even if I change someFunction() to return a different type.

This is really, really useful when writing templates - but I would argue that
it's a good thing even here.

This is one of the things that makes foreach() so useful - I don't need to know
whose opApply() method gets called, if I take a container as an argument to a
template - it can just take *any* container and iterate over it.

Kevin





More information about the Digitalmars-d mailing list