Re: Template constructor in a non-template struct.

2015-02-14 Thread ChrisG via Digitalmars-d-learn
On Monday, 9 February 2015 at 09:52:13 UTC, Marc Schütz wrote: You could also hide the ugly __ctor() call behind a nicely named factory method. Yes, that's pretty much what I ended up doing. Added a couple static member functions like: static Boring CreateWithOption1(args); static Boring C

Re: Template constructor in a non-template struct.

2015-02-09 Thread via Digitalmars-d-learn
On Sunday, 8 February 2015 at 22:19:35 UTC, ChrisG wrote: Thanks bearophile. Your first suggestion about making the struct a template is something I considered. However, because of all the code I've already written that approach would force me to use inheritance or convert a ton of functions to

Re: Template constructor in a non-template struct.

2015-02-08 Thread ChrisG via Digitalmars-d-learn
Thanks bearophile. Your first suggestion about making the struct a template is something I considered. However, because of all the code I've already written that approach would force me to use inheritance or convert a ton of functions to templates. Ick. The __ctor syntax looks like the answer

Re: Template constructor in a non-template struct.

2015-02-08 Thread bearophile via Digitalmars-d-learn
ChrisG: I don't really understand how I'd differentiate a constructor template from a class/struct template. One solution is to use a template struct (struct/class names start with an upper case in D, while typed enum members usually start with a lower case): enum E { option1, option2 }