Private default function arguments
bearophile
bearophileHUGS at lycos.com
Fri Jan 15 01:38:19 PST 2010
Clemens:
> void foo(int x)
> {
> void fooImpl(int x, int depth);
> {
> // ...
> }
>
> fooImpl(x, 0);
> }
OK, I'll use a static nested function then, it's not as clean as adding a "private" attribute, but probably there's not enough need to add other features to the language:
int foo4(int x) {
int foo4inner(int x, depth=0) {
...
foo4inner(x, depth + 1);
...
}
return foo4inner(x);
}
void main() {
int r = foo4(5); // OK
int r = foo4(5, 1); // Error
int r = foo4(5, 0); // Error
}
The compiler probably takes care of always optimize the extra function call away.
Bye and thank you,
bearophile
More information about the Digitalmars-d
mailing list