The Right Approach to Exceptions

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Feb 20 17:29:02 PST 2012


On Tue, Feb 21, 2012 at 12:44:11AM +0000, kennytm wrote:
> "H. S. Teoh" <hsteoh at quickfur.ath.cx> 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.


More information about the Digitalmars-d mailing list