digitalmars.D.learn - Designated initializers to function argument
- Ki Rill (22/22) Jul 11 2023 In C I can do the following:
- Ki Rill (3/10) Jul 11 2023 Ok, this works with DMD v2.103, but does not work with an older
- Steven Schveighoffer (6/17) Jul 11 2023 Yes, I was going to reply that v 2.103 has added (stealthily) named
- IchorDev (4/15) Jul 28 2023 N-no way?! The spec makes no mention of them, is it really safe
- Steven Schveighoffer (5/20) Jul 28 2023 It isn't going away. I would wait a bit for libraries, because you don't...
- bachmeier (3/21) Jul 28 2023 [The
- IchorDev (3/5) Jul 28 2023 No shit, it felt like an eternity. But it's still not in the
- bachmeier (4/10) Jul 28 2023 I'd expect it to appear in the spec after there's a real release.
- Mike Parker (5/12) Jul 28 2023 https://github.com/orgs/dlang/projects/19
In C I can do the following: ```C void apply(struct Appearance a) {...} // usage apply((struct Appearance) { .color = BLACK, .strokeWidth = 4 }); ``` Can I do the same in D without creating a struct variable separately? ```D void apply(Appearance a) {...} // currently accepts Appearance a = { color: BLACK, strokeWidth: 4 }; apply(a); // would like this apply({ color: BLACK, strokeWidth: 4 }); // or this apply(Appearance(color: BLACK, strokeWidth: 4)); // other fields are default initialized: strokeOpacity, fillOpacity, etc... ```
Jul 11 2023
On Tuesday, 11 July 2023 at 15:16:54 UTC, Ki Rill wrote:```D // or this apply(Appearance(color: BLACK, strokeWidth: 4)); // other fields are default initialized: strokeOpacity, fillOpacity, etc... ```Ok, this works with DMD v2.103, but does not work with an older version (I had ldc2 installed based on DMD v2.98).
Jul 11 2023
On 7/11/23 11:22 AM, Ki Rill wrote:On Tuesday, 11 July 2023 at 15:16:54 UTC, Ki Rill wrote:Yes, I was going to reply that v 2.103 has added (stealthily) named parameters *as a partial implementation*. Included in this is struct initializers, and constructors and functions that are *not* templates. If you are willing to use DMD 2.103 and above, you should be good. -Steve```D // or this apply(Appearance(color: BLACK, strokeWidth: 4)); // other fields are default initialized: strokeOpacity, fillOpacity, etc... ```Ok, this works with DMD v2.103, but does not work with an older version (I had ldc2 installed based on DMD v2.98).
Jul 11 2023
On Tuesday, 11 July 2023 at 17:43:43 UTC, Steven Schveighoffer wrote:On 7/11/23 11:22 AM, Ki Rill wrote:N-no way?! The spec makes no mention of them, is it really safe to use them yet?On Tuesday, 11 July 2023 at 15:16:54 UTC, Ki Rill wrote:Yes, I was going to reply that v 2.103 has added (stealthily) named parameters *as a partial implementation*. Included in this is struct initializers, and constructors and functions that are *not* templates. If you are willing to use DMD 2.103 and above, you should be good. -Steveapply(Appearance(color: BLACK, strokeWidth: 4)); // other fields are default initialized: strokeOpacity, fillOpacity,
Jul 28 2023
On 7/28/23 3:35 AM, IchorDev wrote:On Tuesday, 11 July 2023 at 17:43:43 UTC, Steven Schveighoffer wrote:It isn't going away. I would wait a bit for libraries, because you don't want to force your users to require such a recent version of the compiler. Using it in an executable is fine. -SteveOn 7/11/23 11:22 AM, Ki Rill wrote:N-no way?! The spec makes no mention of them, is it really safe to use them yet?On Tuesday, 11 July 2023 at 15:16:54 UTC, Ki Rill wrote:Yes, I was going to reply that v 2.103 has added (stealthily) named parameters *as a partial implementation*. Included in this is struct initializers, and constructors and functions that are *not* templates. If you are willing to use DMD 2.103 and above, you should be good.apply(Appearance(color: BLACK, strokeWidth: 4)); // other fields are default initialized: strokeOpacity, fillOpacity,
Jul 28 2023
On Friday, 28 July 2023 at 07:35:00 UTC, IchorDev wrote:On Tuesday, 11 July 2023 at 17:43:43 UTC, Steven Schveighoffer wrote:[The DIP](https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1030.md) was approved long ago. It was waiting for an implementation.On 7/11/23 11:22 AM, Ki Rill wrote:N-no way?! The spec makes no mention of them, is it really safe to use them yet?On Tuesday, 11 July 2023 at 15:16:54 UTC, Ki Rill wrote:Yes, I was going to reply that v 2.103 has added (stealthily) named parameters *as a partial implementation*. Included in this is struct initializers, and constructors and functions that are *not* templates. If you are willing to use DMD 2.103 and above, you should be good. -Steveapply(Appearance(color: BLACK, strokeWidth: 4)); // other fields are default initialized: strokeOpacity, fillOpacity,
Jul 28 2023
On Friday, 28 July 2023 at 17:04:33 UTC, bachmeier wrote:[The DIP](https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1030.md) was approved long ago. It was waiting for an implementation.No shit, it felt like an eternity. But it's still not in the spec...?
Jul 28 2023
On Friday, 28 July 2023 at 17:07:37 UTC, IchorDev wrote:On Friday, 28 July 2023 at 17:04:33 UTC, bachmeier wrote:I'd expect it to appear in the spec after there's a real release. This is the first I've heard of it being supported, and it sounds like it's incomplete.[The DIP](https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1030.md) was approved long ago. It was waiting for an implementation.No shit, it felt like an eternity. But it's still not in the spec...?
Jul 28 2023
On Friday, 28 July 2023 at 21:07:47 UTC, bachmeier wrote:On Friday, 28 July 2023 at 17:07:37 UTC, IchorDev wrote:https://github.com/orgs/dlang/projects/19 Dennis has been working on this in pieces rather than all at once, as it required modification to multiple parts of the compiler.No shit, it felt like an eternity. But it's still not in the spec...?I'd expect it to appear in the spec after there's a real release. This is the first I've heard of it being supported, and it sounds like it's incomplete.
Jul 28 2023