diff --git a/changelog/dmd.named-arguments.dd b/changelog/dmd.named-arguments.dd new file mode 100644 index 0000000000..ca78b14ea4 --- /dev/null +++ b/changelog/dmd.named-arguments.dd @@ -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)