digitalmars.D.learn - Template Mixin issue
- Mike L. (17/17) Jan 29 2009 Hello,
 - Christopher Wright (11/12) Jan 30 2009 This is a bug. In template specializations, : means equality. In static
 - Christopher Wright (3/9) Jan 30 2009 This is only with template specializations involving templates, by the
 
Hello,
I was wondering why the following does not work:
interface A(Type)
	{ Type blah(); }
template ADefaults(Type, AType : A!(Type))
{
	Type blah()
		{ return Type.init; }
}
class B(Type) : A!(Type)
	{ mixin ADefaults!(Type, B!(Type)); }
void main()
	{ auto x = new B!(int)(); }
It gives the error: test.d(11): mixin ADefault!(int,B) does not match any
template declaration
However, it will compile if you change the ADefaults header to:
template ADefaults(Type, AType)
If the compiler can tell that B!(int) is a type, why can't it tell that it is a
child class of A!(int) ?
 Jan 29 2009
Mike L. wrote:If the compiler can tell that B!(int) is a type, why can't it tell that it is a child class of A!(int) ?This is a bug. In template specializations, : means equality. In static if, : means convertibility. So, you can use: template ADefaults(Type, AType) { static assert (is (AType : A!(Type))); Type blah() { return Type.init; } } http://d.puremagic.com/issues/show_bug.cgi?id=1715 if you want to vote.
 Jan 30 2009
Christopher Wright wrote:Mike L. wrote:This is only with template specializations involving templates, by the way. Template specializations involving any other type are fine.If the compiler can tell that B!(int) is a type, why can't it tell that it is a child class of A!(int) ?This is a bug. In template specializations, : means equality. In static if, : means convertibility.
 Jan 30 2009








 
 
 
 Christopher Wright <dhasenan gmail.com>