auto return for some recursive functions in C++11

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 14 14:29:08 PST 2015


According to Wikipedia:
http://en.wikipedia.org/wiki/C%2B%2B14#Function_return_type_deduction

C++14 is able to compile code like this:


auto correct(int i) {
     if (i == 1)
         return i;
     else
         return correct(i - 1) + i;
}


But not like this:

auto correct(int i) {
     if (i != 1)
         return correct(i - 1) + i;
     else
         return i;
}


D isn't able to compile both. Is it a good idea to allow the 
first function in D too?

Bye,
bearophile


More information about the Digitalmars-d mailing list