Re: Inherit from class based on bool value

2018-11-15 Thread bauss via Digitalmars-d-learn
On Thursday, 15 November 2018 at 08:46:36 UTC, Bienlein wrote: On Tuesday, 13 November 2018 at 07:10:26 UTC, Jamie wrote: I would like my class to inherit from one of two classes based on a boolean value known at compile time. Something like this: void main() { Top!(OPTION.FALSE) top =

Re: Inherit from class based on bool value

2018-11-15 Thread Bienlein via Digitalmars-d-learn
On Tuesday, 13 November 2018 at 07:10:26 UTC, Jamie wrote: I would like my class to inherit from one of two classes based on a boolean value known at compile time. Something like this: void main() { Top!(OPTION.FALSE) top = new Top!(OPTION.FALSE); } enum OPTION { FALSE = 0., TRUE

Re: Inherit from class based on bool value

2018-11-13 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 13 November 2018 at 07:10:26 UTC, Jamie wrote: I would like my class to inherit from one of two classes based on a boolean value known at compile time. Something like this: void main() { Top!(OPTION.FALSE) top = new Top!(OPTION.FALSE); } enum OPTION { FALSE = 0., TRUE

Re: Inherit from class based on bool value

2018-11-13 Thread Jamie via Digitalmars-d-learn
On Tuesday, 13 November 2018 at 07:29:30 UTC, Ali Çehreli wrote: On 11/12/2018 11:10 PM, Jamie wrote: > I would like my class to inherit from one of two classes ... > Is this possible? I can't get it to work in the way I'm showing above. > Cheers I got it working inside an eponymous template. D

Re: Inherit from class based on bool value

2018-11-13 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 13 November 2018 at 07:10:26 UTC, Jamie wrote: Is this possible? I can't get it to work in the way I'm showing above. ...or abstract away Ali's solution: enum OPTION { FALSE, TRUE, } template Select(OPTION opt, IfTrue, IfFalse) { static if (opt == OPTION.TRUE) alias

Re: Inherit from class based on bool value

2018-11-12 Thread Ali Çehreli via Digitalmars-d-learn
On 11/12/2018 11:10 PM, Jamie wrote: > I would like my class to inherit from one of two classes based on a > boolean value known at compile time. Something like this: > > void main() > { > Top!(OPTION.FALSE) top = new Top!(OPTION.FALSE); > } > > enum OPTION > { > FALSE = 0., > TRUE

Inherit from class based on bool value

2018-11-12 Thread Jamie via Digitalmars-d-learn
I would like my class to inherit from one of two classes based on a boolean value known at compile time. Something like this: void main() { Top!(OPTION.FALSE) top = new Top!(OPTION.FALSE); } enum OPTION { FALSE = 0., TRUE = 1. } class One {} class Two {} class Top(OPTION option)