digitalmars.D.learn - Regular Templates May Be `mixin`d?
- surlymoor (18/18) Oct 02 2021 ```d
- Paul Backus (5/11) Oct 02 2021 Source: https://dlang.org/spec/template-mixin.html
- surlymoor (4/16) Oct 02 2021 Lord, I'm careless. Thanks.
- Paul Backus (2/5) Oct 03 2021 Yes, exactly.
```d // Modified sixth example from https://dlang.org/spec/template-mixin.html int y = 3; template Foo() { int abc() { return y; } } void main() { int y = 8; mixin Foo; // local y is picked up, not global y assert(abc() == 8); } ``` This compiles and works. I checked the spec, and I don't see anything; probably missed it, however; mentioning the fact that regular templates may be used with `mixin`. Is this expected?
Oct 02 2021
On Sunday, 3 October 2021 at 02:52:20 UTC, surlymoor wrote:This compiles and works. I checked the spec, and I don't see anything; probably missed it, however; mentioning the fact that regular templates may be used with `mixin`. Is this expected?Yes, this is intentional and expected. From the spec:A TemplateMixin takes an arbitrary set of declarations from the body of a TemplateDeclaration and inserts them into the current context.Source: https://dlang.org/spec/template-mixin.html Notice that it is specified to work with any template declaration, not just one declared as a `mixin template`.
Oct 02 2021
On Sunday, 3 October 2021 at 03:04:29 UTC, Paul Backus wrote:On Sunday, 3 October 2021 at 02:52:20 UTC, surlymoor wrote:Lord, I'm careless. Thanks. So the difference between a `mixin template` and a regular one is that the former may only be used with a `mixin` statement?This compiles and works. I checked the spec, and I don't see anything; probably missed it, however; mentioning the fact that regular templates may be used with `mixin`. Is this expected?Yes, this is intentional and expected. From the spec:A TemplateMixin takes an arbitrary set of declarations from the body of a TemplateDeclaration and inserts them into the current context.Source: https://dlang.org/spec/template-mixin.html Notice that it is specified to work with any template declaration, not just one declared as a `mixin template`.
Oct 02 2021
On Sunday, 3 October 2021 at 03:34:19 UTC, surlymoor wrote:Lord, I'm careless. Thanks. So the difference between a `mixin template` and a regular one is that the former may only be used with a `mixin` statement?Yes, exactly.
Oct 03 2021