@@ -1494,6 +1494,7 @@ $(H2 $(LNAME2 nested-templates, Nested Templates))
1494
1494
instantiated functions will implicitly capture the context of the
1495
1495
enclosing scope.)
1496
1496
1497
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
1497
1498
----
1498
1499
class C
1499
1500
{
@@ -1525,11 +1526,46 @@ $(H2 $(LNAME2 nested-templates, Nested Templates))
1525
1526
assert(c.num == 10);
1526
1527
}
1527
1528
----
1529
+ )
1528
1530
1529
- $(P Above, $(D Foo!().foo) will work just the same as a member function
1531
+ $(P Above, $(D Foo!().foo) will work just the same as a `final` member function
1530
1532
of class $(D C), and $(D Bar!().bar) will work just the same as a nested
1531
1533
function within function $(D main$(LPAREN)$(RPAREN)).)
1532
1534
1535
+ $(H3 $(LNAME2 limitations, Aggregate Type Limitations))
1536
+
1537
+ $(P A nested template cannot add non-static fields to an aggregate type.
1538
+ Fields declared in a nested template will be implicitly `static`.)
1539
+ $(P A nested template cannot add virtual functions to a class or interface.
1540
+ Methods inside a nested template will be implicitly `final`.)
1541
+
1542
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1543
+ ------
1544
+ class Foo
1545
+ {
1546
+ template TBar(T)
1547
+ {
1548
+ T xx; // becomes a static field of Foo
1549
+ void func(T) {} // implicitly final
1550
+ //abstract void baz(); // error, final functions cannot be abstract
1551
+
1552
+ static T yy; // Ok
1553
+ static void func(T t, int y) {} // Ok
1554
+ }
1555
+ }
1556
+
1557
+ void main()
1558
+ {
1559
+ alias bar = Foo.TBar!int;
1560
+ bar.xx++;
1561
+ //bar.func(1); // error, no this
1562
+
1563
+ auto o = new Foo;
1564
+ o.TBar!int.func(1); // OK
1565
+ }
1566
+ ------
1567
+ )
1568
+
1533
1569
$(H3 $(LNAME2 implicit-nesting, Implicit Nesting))
1534
1570
1535
1571
$(P If a template has a $(RELATIVE_LINK2 aliasparameters, template alias parameter),
@@ -1753,26 +1789,6 @@ $(GNAME Constraint):
1753
1789
auto y = Bar!double; // Error, double does not satisfy constraint
1754
1790
---
1755
1791
1756
- $(H2 $(LNAME2 limitations, Limitations))
1757
-
1758
- $(P Templates cannot be used to add non-static fields or
1759
- virtual functions to classes or interfaces.
1760
- For example:)
1761
-
1762
- ------
1763
- class Foo
1764
- {
1765
- template TBar(T)
1766
- {
1767
- T xx; // becomes a static field of Foo
1768
- int func(T) { ... } // non-virtual
1769
-
1770
- static T yy; // Ok
1771
- static int func(T t, int y) { ... } // Ok
1772
- }
1773
- }
1774
- ------
1775
-
1776
1792
$(SPEC_SUBNAV_PREV_NEXT operatoroverloading, Operator Overloading, template-mixin, Template Mixins)
1777
1793
)
1778
1794
0 commit comments