On Tue, Feb 21, 2012 at 12:44:11AM +0000, kennytm wrote:
> "H. S. Teoh" <[email protected]> wrote:
> > On Mon, Feb 20, 2012 at 03:17:44PM -0500, Nick Sabalausky wrote:
[...]
> >> A better solution has already been proposed:
> >> 
> >>     class AcmeException : Exception
> >>     {
> >>         mixin inheritCtors!();  // Actual name open for bikeshedding
> >>     }
> > 
> > Somewhere in this giant thread, somebody has proposed that there should
> > be language support for implicitly inheriting base class ctors. That is,
> > if you write:
> > 
> >     class Base {
> >             this(string, int, float) { ... }
> >     }
> > 
> >     class Derived : Base { }
> > 
> > then the compiler will automatically insert this into Derived:
> > 
> >     this(string s, int i, float f) {
> >             super(s, i, f);
> >     }
[...]
> Note that this should work:
> 
> class Derived : Base {
>   this(T...)(T values) { 
>     super(values);
>   }
> }

You're right, we *could* just put this in a template, which I believe is
what inheritCtors() does:

        mixin template inheritCtors() {
                this(T...)(T values) {
                        super(values);
                }
        }

        class Derived1 : Base {
                inheritCtors!();
        }

        class Derived2 : Base {
                inheritCtors!();
        }

        ... etc.


T

-- 
Debian GNU/Linux: Cray on your desktop.

Reply via email to