@@ -1471,6 +1471,7 @@ $(H2 $(LNAME2 nested-templates, Nested Templates))
1471
1471
instantiated functions will implicitly capture the context of the
1472
1472
enclosing scope.)
1473
1473
1474
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
1474
1475
----
1475
1476
class C
1476
1477
{
@@ -1502,30 +1503,45 @@ $(H2 $(LNAME2 nested-templates, Nested Templates))
1502
1503
assert(c.num == 10);
1503
1504
}
1504
1505
----
1506
+ )
1505
1507
1506
- $(P Above, $(D Foo!().foo) will work just the same as a member function
1508
+ $(P Above, $(D Foo!().foo) will work just the same as a `final` member function
1507
1509
of class $(D C), and $(D Bar!().bar) will work just the same as a nested
1508
1510
function within function $(D main$(LPAREN)$(RPAREN)).)
1509
1511
1510
- $(H3 $(LNAME2 limitations, Limitations))
1512
+ $(H3 $(LNAME2 limitations, Aggregate Type Limitations))
1511
1513
1512
- $(P Templates cannot be used to add non-static fields or
1513
- virtual functions to classes or interfaces.
1514
- For example:)
1514
+ $(P A nested template cannot add non-static fields to an aggregate type.
1515
+ Fields declared in a nested template will be implicitly `static`.)
1516
+ $(P A nested template cannot add virtual functions to a class or interface.
1517
+ Methods inside a nested template will be implicitly `final`.)
1515
1518
1519
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1516
1520
------
1517
1521
class Foo
1518
1522
{
1519
1523
template TBar(T)
1520
1524
{
1521
- T xx; // becomes a static field of Foo
1522
- int func(T) { ... } // non-virtual
1525
+ T xx; // becomes a static field of Foo
1526
+ void func(T) {} // implicitly final
1527
+ //abstract void baz(); // error, final functions cannot be abstract
1523
1528
1524
- static T yy; // Ok
1525
- static int func(T t, int y) { ... } // Ok
1529
+ static T yy; // Ok
1530
+ static void func(T t, int y) {} // Ok
1526
1531
}
1527
1532
}
1533
+
1534
+ void main()
1535
+ {
1536
+ alias bar = Foo.TBar!int;
1537
+ bar.xx++;
1538
+ //bar.func(1); // error, no this
1539
+
1540
+ auto o = new Foo;
1541
+ o.TBar!int.func(1); // OK
1542
+ }
1528
1543
------
1544
+ )
1529
1545
1530
1546
$(H3 $(LNAME2 implicit-nesting, Implicit Nesting))
1531
1547
0 commit comments