Skip to content

Commit c32fef2

Browse files
authored
[spec] Tweak docs on default arguments (#3621)
Minor tweaks. Add link to function type aliases.
1 parent e049ce7 commit c32fef2

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

spec/declaration.dd

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,18 +411,20 @@ assert(S.j == 4);
411411
$(H3 $(LNAME2 alias-function, Aliasing a Function Type))
412412

413413
$(P Function types can be aliased:)
414+
415+
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
414416
---
415417
alias Fun = int(string p);
416-
int fun(string){return 0;}
418+
int fun(string) {return 0;}
417419
static assert(is(typeof(fun) == Fun));
418420

419421
alias MemberFun1 = int() const;
420422
alias MemberFun2 = const int();
421423
// leading attributes apply to the func, not the return type
422424
static assert(is(MemberFun1 == MemberFun2));
423425
--------------------
424-
425-
$(P Aliases can be used to call a function with different default
426+
)
427+
$(P Type aliases can be used to call a function with different default
426428
arguments, change an argument from required to default or vice versa:)
427429

428430
$(SPEC_RUNNABLE_EXAMPLE_RUN
@@ -434,7 +436,7 @@ void main() {
434436
foo(); // prints v: 6
435437
foo(8); // prints v: 8
436438
Bar bar = &barbar;
437-
// bar(4); // compilation error, because the `Bar` alias
439+
//bar(4); // compilation error, because the `Bar` alias
438440
// requires an explicit 2nd argument
439441
barbar(4); // prints a: 4, b: 6, c: 7
440442
bar(4, 5); // prints a: 4, b: 5, c: 9

spec/function.dd

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ void main()
16461646

16471647
$(P See Also: $(RELATIVE_LINK2 lazy_variadic_functions, Lazy Variadic Functions))
16481648

1649-
$(H3 $(LNAME2 function-default-args, Function Default Arguments))
1649+
$(H3 $(LNAME2 function-default-args, Default Arguments))
16501650

16511651
$(P Function parameter declarations can have default values:)
16521652

@@ -1664,14 +1664,14 @@ foo(4); // same as foo(4, 3);
16641664
---
16651665
module m;
16661666
private immutable int b;
1667-
pure void g(int a=b){}
1667+
pure void g(int a = b) {}
16681668
---
16691669
---
16701670
import m;
16711671
int b;
16721672
pure void f()
16731673
{
1674-
g(); // ok, uses m.b
1674+
g(); // ok, uses m.b
16751675
}
16761676
---
16771677

@@ -1680,21 +1680,25 @@ pure void f()
16801680
---
16811681
module m;
16821682
int b;
1683-
pure void g(int a=b){}
1683+
pure void g(int a = b) {}
16841684
---
16851685
---
16861686
import m;
16871687
enum int b = 3;
16881688
pure void f()
16891689
{
1690-
g(); // error, cannot access mutable global `m.b` in pure function
1690+
g(); // error, cannot access mutable global `m.b` in pure function
16911691
}
16921692
---
16931693

16941694
$(P If the default value for a parameter is given, all following
16951695
parameters must also have default values.
16961696
)
16971697

1698+
$(P See also: function type aliases
1699+
$(DDSUBLINK spec/declaration, alias-function, with default values).)
1700+
1701+
16981702
$(H3 $(LNAME2 return-ref-parameters, Return Ref Parameters))
16991703

17001704
$(P Return ref parameters are used with

0 commit comments

Comments
 (0)