Signature conditions

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Feb 10 12:08:04 PST 2012


On Fri, Feb 10, 2012 at 08:53:58PM +0100, Timon Gehr wrote:
> On 02/10/2012 07:50 PM, H. S. Teoh wrote:
[...]
> >On that note, I discovered that if you want signature constraints on
> >a derived class, the syntax is unbearably ugly:
> >
> >	class Derived(T)
> >		if (/* conditions */)
> >		: Base
> >	{
> >		...
> >	}
> >
> >I would have expected the syntax to be like this instead:
> >
> >	class Derived(T) : Base
> >		if (/* conditions */)
> >	{
> >		...
> >	}
[...]
> It makes more sense as it is. Consider the instantiation
> 'Derived!int' and the condition 'is(typeof(T)==class)'.

Well, to me, the "if" condition should apply to the entire class
specification "class Derived(T) : Base", and not just to Derived(T). For
example, something like this wouldn't be in a logical sequence:

	class Derived(T)
		if (is(Base!T ...))
		: Base!T
	{
		...
	}

since you'll want the condition to restrict what values Base!T can take
on. This would be more readable:

	class Derived(T) : Base!T
		if (is(Base!T ...))
	{
		...
	}


T

-- 
"I'm running Windows '98."
"Yes."
"My computer isn't working now."
"Yes, you already said that."
-- User-Friendly


More information about the Digitalmars-d-learn mailing list