Named Arguments Status Update - Overloading by name

bachmeier no at spam.net
Wed Apr 10 13:47:19 UTC 2024


On Wednesday, 10 April 2024 at 12:18:06 UTC, jmh530 wrote:

> That line with `auto h` can also be written `auto h = g = f = 
> 4.7;` and you get the same result.
>
> Learn something new every day, I guess. The function spec [1] 
> doesn't talk about this, but it must be something with an 
> assign expression [2] of f = a getting re-written to f(a) for 
> functions.
>
> [1] https://dlang.org/spec/function.html
> [2] https://dlang.org/spec/expression.html#assign_expressions

I learned about it from the properties chapter in Ali's book: 
http://ddili.org/ders/d.en/property.html

It's particularly useful for clean interfaces when you're 
wrapping structs allocated by a C library. You may have to do 
various operations behind the scenes, like converting D strings 
to their C counterparts so the data can be used internally, but 
you still want to be able to work with it in the natural way 
`x.names = ["blue", "green", "red"]`.


More information about the Digitalmars-d mailing list