return in void functions

Nick Sabalausky a at a.a
Fri Mar 6 10:00:35 PST 2009


"Georg Wrede" <georg.wrede at iki.fi> wrote in message 
news:goqlhm$bg5$1 at digitalmars.com...
> bearophile wrote:
>> Nick Sabalausky:
>>> There has to be a better way to handle that.
>>
>> Possible idea: allowing functions too (and not just
>> function templates as in D2) to have an "auto" return type?
>
> void main()
> {
>     auto a = f();
>     // Here, store a in a struct, i.e. you need to know the type
>     // so that you can have the right kind of struct for it.
> }
>
> auto f()
> {
>     auto c = g();
>     return c;
> }
>
>
> auto g()
> {
>     auto c = h();
>     return c;
> }
>
> Then in a library (probably not even documented with the actual return 
> type -- an understandable omission by this time...)
>
> auto h()
> {
>     auto c = i();
>     return c;
> }
>
> auto i()
> {
>     auto c = j(); // where j() is a non-public function.
>     return c;
> }
>
>
> ...etc. So, isn't it easier for the programmer to know what the data type 
> is, without going for goose chases every time?

You could probably just do:

auto a = f();
Stdout.formatln("{}", typeof(a).stringof); // Debug

But I still wouldn't want to have to do that.

Of course, that could arguably be solved by having automatic documentation 
automatically resolve the "auto". Although that would require 3rd party doc 
generators to do much more involved parsing.





More information about the Digitalmars-d mailing list