Optional out parameter of function
Jonathan M Davis
jmdavisProg at gmx.com
Wed Nov 27 02:15:17 PST 2013
On Wednesday, November 27, 2013 10:57:42 Joseph Rushton Wakeling wrote:
> On 27/11/13 10:45, bearophile wrote:
> > It's useless code, you can't have ref variadic, sorry.
>
> Ack. :-( I just tried it out myself and found the same thing.
Personally, I think that it's by far the best approach to just do
int foo(int i)
{
int j;
return foo(i, j);
}
It's clean, and I really don't see a big problem with it. But if you _really_
don't want to do that, you can always create a dummy variable and do something
like
int dummy;
int foo(int i, out int j = dummy)
{
...
}
But I'd advise against it, since it strikes me as rather messy, and I really
don't see any problem with just creating a wrapper function. It's the kind of
thing that you already have to pretty much any time that you try and have a
function accept const ref for an efficiency boost, since ref doesn't accept
rvalues. A bit annoying perhaps, but not a big deal.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list