Re: Template mixins and struct constructors

2016-03-03 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 20:39:57 UTC, Adam D. Ruppe wrote: On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: Is it by design or is it a bug? And, if it is by design, what is the reason for that? That's by design. It allows you to override names from a template mixin like

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
Dne 2.3.2016 v 21:39 Adam D. Ruppe via Digitalmars-d-learn napsal(a): On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: Is it by design or is it a bug? And, if it is by design, what is the reason for that? That's by design. It allows you to override names from a template mixi

Re: Template mixins and struct constructors

2016-03-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: Is it by design or is it a bug? And, if it is by design, what is the reason for that? That's by design. It allows you to override names from a template mixin like inheritance but no runtime cost. Read my tip of the week here to

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 14:50:15 UTC, Adrian Matoga wrote: On Wednesday, 2 March 2016 at 14:36:59 UTC, Daniel Kozak wrote: OK maybe this one: template AddField(T) { T b; this(Args...)(T b, auto ref Args args) { this.b = b; this(args); } this(int a) {

Re: Template mixins and struct constructors

2016-03-02 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 14:36:59 UTC, Daniel Kozak wrote: OK maybe this one: template AddField(T) { T b; this(Args...)(T b, auto ref Args args) { this.b = b; this(args); } this(int a) { this.a = a; } } struct Bar { int a; mixin Add

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 13:18:23 UTC, Adrian Matoga wrote: On Wednesday, 2 March 2016 at 12:48:47 UTC, Daniel Kozak wrote: On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: (...) You can use string mixins: template AddField(T) { enum AddField = T.stringof ~ ` b;

Re: Template mixins and struct constructors

2016-03-02 Thread Adrian Matoga via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 12:48:47 UTC, Daniel Kozak wrote: On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: (...) You can use string mixins: template AddField(T) { enum AddField = T.stringof ~ ` b; this(Args...)(` ~ T.stringof ~ ` b, auto ref Args args)

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: I can do this: struct Foo { int a; string b; this(int a) { this.a = a; } this(Args...)(string b, auto ref Args args) { this.b = b; this(args); } } unittest { auto foo1 = Foo(5); auto foo2

Re: Template mixins and struct constructors

2016-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 12:27:04 UTC, Adrian Matoga wrote: I can do this: struct Foo { int a; string b; this(int a) { this.a = a; } this(Args...)(string b, auto ref Args args) { this.b = b; this(args); } } unittest { auto foo1 = Foo(5); auto foo2

Template mixins and struct constructors

2016-03-02 Thread Adrian Matoga via Digitalmars-d-learn
I can do this: struct Foo { int a; string b; this(int a) { this.a = a; } this(Args...)(string b, auto ref Args args) { this.b = b; this(args); } } unittest { auto foo1 = Foo(5); auto foo2 = Foo("foo", 15); } However, the following code is invalid: mix