auto return for some recursive functions in C++11
ketmar via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jan 14 16:18:38 PST 2015
On Thu, 15 Jan 2015 00:05:30 +0000
Xinok via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> Well, the error the compiler prints is:
>
> Error: forward reference to inferred return type of function call
> 'correct'
>
> I played with it a bit and it seems to deduce a common type from
> all the return statements, which would be more in the style of D
> anyways (take type deduction for arrays). For example, the
> following code prints "float" rather than "int":
>
> import std.stdio;
>
> auto one(int i)
> {
> if(i > 0)
> return cast(int)i;
> else
> return cast(float)i;
> }
>
> void main()
> {
> writeln(typeid(typeof(one(10))));
> }
i remember that there was some discussion about this, but it's all i
can remember about it. ;-)
there were some inconsistencies with deducing return type, AFAIR, but i
don't remember if it leads to some fixes or not. if ony i wasn't so
lazy and take some notes...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150115/6a58b861/attachment.sig>
More information about the Digitalmars-d
mailing list