@@ -1481,30 +1481,36 @@ $(GNAME ConstructorTemplate):
1481
1481
1482
1482
$(H2 $(LNAME2 variable-template, Enum & Variable Templates))
1483
1483
1484
- $(P Like aggregates and functions, manifest constant and variable
1485
- declarations can have template parameters, providing there is
1484
+ $(P Like aggregates and functions, $(DDSUBLINK spec/declaration, variable-declarations, variable
1485
+ declarations) and manifest constants can have template parameters, providing there is
1486
1486
an $(GLINK2 declaration, Initializer):)
1487
1487
1488
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1488
1489
------
1489
- enum string constant(TL... ) = TL.stringof ;
1490
+ enum bool within(alias v, T ) = v <= T.max && v >= T.min ;
1490
1491
ubyte[T.sizeof] storage(T) = 0;
1491
- auto array(alias a) = a;
1492
+ const triplet(alias v) = [v, v+1, v+2];
1493
+
1494
+ static assert(within!(-128F, byte));
1495
+ static assert(storage!(int[2]).length == 8);
1496
+ static assert(triplet!3 == [3, 4, 5]);
1492
1497
------
1498
+ )
1493
1499
1494
- $(P These declarations are transformed into templates :)
1500
+ $(P Those declarations are transformed into these *TemplateDeclaration*s :)
1495
1501
1496
1502
------
1497
- template constant(TL... )
1503
+ template within(alias v, T )
1498
1504
{
1499
- enum string constant = TL.stringof ;
1505
+ enum bool within = v <= T.max && v >= T.min ;
1500
1506
}
1501
1507
template storage(T)
1502
1508
{
1503
1509
ubyte[T.sizeof] storage = 0;
1504
1510
}
1505
- template array (alias a )
1511
+ template triplet (alias v )
1506
1512
{
1507
- auto array = a ;
1513
+ const triplet = [v, v+1, v+2] ;
1508
1514
}
1509
1515
------
1510
1516
0 commit comments