Skip to content

Commit 5936350

Browse files
authored
[spec/template] Tweak template value parameters (#3835)
* [spec/template] Tweak template value parameters Use list of argument kinds, add booleans & characters. Use '*valid* template value arguments' for clarity. Tweak example to use enum instead of function. * Preclude expressions of type void; tighten 'valid arguments' * Restore floating point (oops)
1 parent 06b69f9 commit 5936350

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

spec/template.dd

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,23 +525,26 @@ $(GNAME TemplateValueParameterDefault):
525525
)
526526

527527
$(P A template value parameter can take an argument of any expression which can
528-
be statically evaluated at compile time.
529-
Template value arguments can be integer values, floating point values,
530-
nulls, string values, array literals of template value arguments,
531-
associative array literals of template value arguments,
532-
or struct literals of template value arguments.)
528+
be statically evaluated at compile time as one of the following:)
529+
530+
* A `bool`, character, integer, floating point or string value
531+
* `null`
532+
* An array literal whose elements could be valid template value arguments
533+
* An associative array literal whose keys and values could each be valid
534+
template value arguments
535+
* A struct literal whose arguments could be valid template value arguments
533536

534537
$(SPEC_RUNNABLE_EXAMPLE_RUN
535538
-----
536539
template foo(string s)
537540
{
538-
string bar() { return s ~ " betty"; }
541+
enum string bar = s ~ " betty";
539542
}
540543

541544
void main()
542545
{
543546
import std.stdio;
544-
writeln(foo!("hello").bar()); // prints: hello betty
547+
writeln(foo!("hello").bar); // prints: hello betty
545548
}
546549
-----
547550
)

0 commit comments

Comments
 (0)