Set optional function parameter
Andrey
saasecondbox at yandex.ru
Fri Aug 17 08:52:53 UTC 2018
Hello,
In D there is a nice function:
> auto Tuple!(int,"status",string,"output") executeShell (
> scope const(char)[] command,
> const(string[string]) env = cast(const(string[string]))null,
> Config config = cast(Config)0,
> ulong maxOutput = 18446744073709551615LU,
> scope const(char)[] workDir = null,
> string shellPath = nativeShell()
>) @trusted;
It has got 5 optional parameters. For example I want set only the
fifth and all other leave with default values.
If it was C/C++ then I would write:
> executeShell("my_command", nullptr, 0, 18446744073709551615,
> nullptr, "my/path");
Long and boring...
What about D? Does it support something like this:
> executeShell("my_command", shellPath = "my/path");
or
> executeShell("my_command", default, default, default, default,
> "my/path");
I mean - can I skip some arguments and set only one that I want?
Hm, Python, it seems to me, support this feature.
More information about the Digitalmars-d-learn
mailing list