On Monday, 11 September 2023 at 23:47:33 UTC, H. S. Teoh wrote:
Since the type of the parameter is already known, the compiler
does not need me to repeat the type name. It already knows
enough to figure it out on its own. "Don't Repeat Yourself"
(DRY).
I think there are 3 possibilities,
On Monday, 11 September 2023 at 17:51:04 UTC, BoQsc wrote:
I would like to set function's default struct for a function in
a way that it would be visible for the reader to see what
options are set. Something like `Options option =
{silenceErrors: false}`
If the function's defaults will
On Mon, Sep 11, 2023 at 10:39:00PM +, Salih Dincer via Digitalmars-d-learn
wrote:
> On Monday, 11 September 2023 at 22:13:25 UTC, H. S. Teoh wrote:
> >
> > Because sometimes I want a specific type.
> >
>
> it's possible...
>
> ```d
> alias ST = Options;
> void specificType(ST option =
On Monday, 11 September 2023 at 19:59:37 UTC, ryuukk_ wrote:
I would love to be able to use C style designated
initialization everywhere too..
Recent version of D added named arguments so you can do
something like:
```D
void someFunction(Options option = Options(silenceErrors:
false))
On Monday, 11 September 2023 at 22:13:25 UTC, H. S. Teoh wrote:
Because sometimes I want a specific type.
it's possible...
```d
alias ST = Options;
void specificType(ST option = ST())
{
if(option)
{
assert(false);
} else
assert(true);
}
void main()
{
specificType(); // No
On Mon, Sep 11, 2023 at 10:05:11PM +, Salih Dincer via Digitalmars-d-learn
wrote:
> On Monday, 11 September 2023 at 20:17:09 UTC, H. S. Teoh wrote:
> >
> > Someone should seriously come up with a way of eliminating the
> > repeated type name in default parameters.
>
> Why not allow it to be
On Monday, 11 September 2023 at 20:17:09 UTC, H. S. Teoh wrote:
Someone should seriously come up with a way of eliminating the
repeated type name in default parameters.
Why not allow it to be flexible enough by using a template
parameter?
```d
enum Options : bool
{
silenceErrorsOff,
On Mon, Sep 11, 2023 at 07:59:37PM +, ryuukk_ via Digitalmars-d-learn wrote:
[...]
> Recent version of D added named arguments so you can do something
> like:
>
> ```D
> void someFunction(Options option = Options(silenceErrors: false))
> ```
>
> I don't like the useless repeating "option
On Monday, 11 September 2023 at 17:51:04 UTC, BoQsc wrote:
https://docarchives.dlang.io/v2.073.0/spec/struct.html#struct-literal
I would like to set function's default struct for a function in
a way that it would be visible for the reader to see what
options are set. Something like `Options
On Monday, 11 September 2023 at 17:51:04 UTC, BoQsc wrote:
Here is an example of what I would hope for to work but it
surely does not work:
If I were you I would use enum, look at my code:
```d
enum Options
{
silenceErrors = false
}
void someFunction (Options option =
https://docarchives.dlang.io/v2.073.0/spec/struct.html#struct-literal
I would like to set function's default struct for a function in a
way that it would be visible for the reader to see what options
are set. Something like `Options option = {silenceErrors: false}`
Here is an example of
11 matches
Mail list logo