return in void functions

Georg Wrede georg.wrede at iki.fi
Fri Mar 6 00:06:13 PST 2009


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?



More information about the Digitalmars-d mailing list