Bug 19530 – New proposed syntax for mixins

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-12-31T05:09:17Z
Last change time
2018-12-31T14:38:13Z
Assigned to
No Owner
Creator
Victor Porton

Comments

Comment #0 by porton — 2018-12-31T05:09:17Z
The programmer sometimes needs to instantiate mixin templates with the same arguments repeatedly, like: mixin template A(int x, float y) { // ... } mixin template B(int x, float y) { // ... } I propose to shorten the above code with the following syntax: template composite(int x, float y) { mixin A { // ... } mixin B { // ... } } // ... struct Test { mixin composite(1, 2.0); }
Comment #1 by dhasenan — 2018-12-31T06:26:29Z
Proposals like this should go through the DIP process -- see https://github.com/dlang/DIPs/blob/master/PROCEDURE.md That should ensure that, at a minimum, your proposal is described thoroughly enough to understand.
Comment #2 by destructionator — 2018-12-31T14:29:32Z
You can just define a third template that mixes in the first two. mixin template A(int x, float y) { // ... } mixin template B(int x, float y) { // ... } mixin template composite(int x, float y) { mixin A!(x, y); mixin B!(x, y); } struct Test { mixin composite!(1, 2.0); } That works today.
Comment #3 by porton — 2018-12-31T14:32:00Z
This does not solve my problem. I want the possibility to _selectively_ (at my disposal, that is both or only A or only B) add mixins A or B without the necessity to pass template parameters two times. Your example does not solve this problem.
Comment #4 by destructionator — 2018-12-31T14:38:13Z
You can also save template argument lists as a separate alias and reuse them. // save the args as a new name to reuse import std.meta; alias MyArgs = AliasSeq!(1, 2.0); struct Test { mixin A!MyArgs; mixin B!MyArgs; }