www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Specialized TemplateIdentifer for template parameters

reply knjhara <knjhara cc.kyoto-su.ac.jp> writes:
Hi, all.

I made following code, but cannot compiled it.

--------------------------------------------------
template Connect(alias Adapter1, alias Adapter2)
{
	template AdapterImpl(alias Adapter, alias PrevProc)
	{
		mixin Adapter;		// line 5
		
		int defaultProc(uint msg)
		{
			return PrevProc(msg);
		}
	}
	
	int callDefProc(uint msg)
	{
		...
	}
	
	mixin AdapterImpl!(Adapter2, callDefProc) adptr2;
	mixin AdapterImpl!(Adapter1, adptr2.proc) adptr1;
}

template TestAdapter1()
{
	int proc(uint msg)
	{
		...
		return defaultProc(msg);
	}
}

template TestAdapter2(int param)
{
	int proc(uint msg)
	{
		...
		return defaultProc(msg);
	}
}

class TestClass
{
	mixin Connect!(
		TestAdapter1,			// ok
		TestAdapter2!(1024)		// failed ... mixinTest.d(5): mixin Adapter is
not a template
	);
}
--------------------------------------------------

Do specialized template identifers enable templates to use parameter?

And is it make to use what mixin in template scopes is given alias
TemplateIdentifer what to be specialized ?

- knjhara
Feb 15 2006
parent reply Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
It doesn't work because well... Adapter2 alias in the Connect template
is not a template, but a template instance. The following seems to work:

template TestAdapter2(int param)
{
	template TestAdapter2()
	{
		int proc(uint msg)
		{
	//		...
			return defaultProc(msg);
		}
	}
}


That way, TestAdapter2!(1024) really gives you a template, the inner
parameter-less TestAdapter2().



-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d-pu s+: a-->----- C+++$>++++ UL P+ L+ E--- W++ N++ o? K? w++ !O
!M V? PS- PE- Y PGP t 5 X? R tv-- b DI- D+ G e>+++ h>++ !r !y
------END GEEK CODE BLOCK------

Tomasz Stachowiak  /+ a.k.a. h3r3tic +/
Feb 15 2006
parent knjhara <knjhara cc.kyoto-su.ac.jp> writes:
Tom S wrote:
 It doesn't work because well... Adapter2 alias in the Connect template
 is not a template, but a template instance. The following seems to work:
 
 template TestAdapter2(int param)
 {
 	template TestAdapter2()
 	{
 		int proc(uint msg)
 		{
 	//		...
 			return defaultProc(msg);
 		}
 	}
 }
 
 
 That way, TestAdapter2!(1024) really gives you a template, the inner
 parameter-less TestAdapter2().
Thank you for answering my poor English, it worked. But, it means that passing specialized temlates to temlate is impossible. I want to suggest for Specialized Template Identifer as follows: mixin Connect!( TestAdapter1, TestAdapter2(100) // this is a specialized identifer, not instance ); What do you think? -knjhara
Feb 15 2006