mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Add changelog for named arguments (#16262)
This commit is contained in:
parent
1ca600b46f
commit
310a2d7ea6
1 changed files with 41 additions and 0 deletions
41
changelog/dmd.named-arguments.dd
Normal file
41
changelog/dmd.named-arguments.dd
Normal file
|
@ -0,0 +1,41 @@
|
|||
Named arguments for functions have been implemented and documented
|
||||
|
||||
When calling a function, arguments may be preceded with a parameter name for purposes of clarity and flexible ordering.
|
||||
Consequently, default arguments need not be at the end of the parameter list anymore.
|
||||
|
||||
---
|
||||
void createWindow(bool fullScreen = false, int width, int height, string title);
|
||||
|
||||
void main()
|
||||
{
|
||||
createWindow(title: "Skynet", width: 1280, height: 720);
|
||||
}
|
||||
---
|
||||
|
||||
Named arguments can also be used in struct/union literals.
|
||||
A union can now be initialized by setting a field different than the first one.
|
||||
|
||||
---
|
||||
union U
|
||||
{
|
||||
float asFloat;
|
||||
uint asInt;
|
||||
}
|
||||
|
||||
auto u0 = U(1.0); // this sets the `asFloat` field
|
||||
auto u1 = U(asInt: 0x3F800000); // formerly not possible
|
||||
---
|
||||
|
||||
Relevant specification pages are:
|
||||
$(UL
|
||||
$(LI $(DDSUBLINK spec/struct, struct-literal, Struct Literals))
|
||||
$(LI $(DDSUBLINK spec/struct, anonymous, Anonymous Structs and Unions))
|
||||
$(LI $(DDSUBLINK spec/expression, argument-parameter-matching, Matching Arguments to Parameters))
|
||||
$(LI $(DDSUBLINK spec/function, function-overloading, Function Overloading))
|
||||
)
|
||||
|
||||
Note that the implementation for regular functions and struct literals has been around since dmd 2.103, but it was undocumented and wouldn't work with template functions.
|
||||
|
||||
This implements [DIP1030](https://www.dlang.org/dips/1030) for *function arguments*, but named *template arguments* are not implemented yet.
|
||||
Also, there are still implementation details to be ironed out which the DIP doesn't specify, such as how named arguments interact with tuples.
|
||||
For more information, see: [Named Arguments Status Update](https://forum.dlang.org/post/bynneksajyfyadwndsbm@forum.dlang.org)
|
Loading…
Add table
Add a link
Reference in a new issue