On 01/04/2012 11:19 PM, Caligo wrote:
I have a function that looks something like this:

bool fun(double theta, out A a, out B b, out C c){  /* ... */ }

if fun() returns false, then nothing is supposed to be assigned to a,
b, c.  If it returns true, then values are assigned to a, b, c.  Also,
there are two ways to call fun():  If I'm interested in the return
value only, then

1. fun(theta);

otherwise,

2. fun(theta, a, b, c);

Obviously, method #1 won't work because there is no such thing as:

bool fun(double theta, out A a = void, out B b = void, out C c =
void){  /* ... */ }

is there?

So, I have to lose 'out' and use pointers instead:

bool fun(double theta, A* a = null, B* b = null, C* c = null){  /* ... */ }

I don't want to use a variadic function for this either because it's
not really a variadic function.

1. Are there any other solutions ?

Yes. Use overloading.

This would work:

bool fun(double theta, out A a, out B b, out C c){  /* ... */ }
bool fun(double theta){
    A a; B b; C c;
    return fun(theta,a,b,c);
}

Or this:

private bool funImpl(double theta, A* a = null, B* b = null, C* c = null){ /* ... */ }

bool fun(double theta, out A a, out B b, out C c){return funImpl(theta,&a,&b,&c);
bool fun(double theta){return funImpl(theta);}


2. Would it make sense to have 'out default argument of void' in D?

void initializer means uninitialized. I don't think that can do what you want.

Reply via email to