auto return for some recursive functions in C++11

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 14 16:17:45 PST 2015


Xinok:

>     auto one(int i)
>     {
>         if(i > 0)
>             return cast(int)i;
>         else
>             return cast(float)i;
>     }

With recent D2 compilers I suggest you to get used to write code 
like that like this:


     auto one(int i)
     {
         if(i > 0)
             return int(i);
         else
             return float(i);
     }

It's better to minimize the usage of cast().

Bye,
bearophile


More information about the Digitalmars-d mailing list