www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Getting usages of template

reply Carlin St Pierre <carlin.stpierre gmail.com> writes:
Is it possible to get the list of usages of a template during 
compile time?

For example:

class Foo
{
	void bar(T)(T t)
	{

	}
}

void main()
{
	Foo foo = new Foo;
	foo.bar(1); // int
	foo.bar(2f); // float
	foo.bar("3"); // string
}

// pragma(msg, TemplateThatGetsTemplateUsages!(Foo.bar)) would 
print:
// (int, float, string)
Nov 17 2016
next sibling parent Stefan Koch <uplink.coder googlemail.com> writes:
On Thursday, 17 November 2016 at 09:40:45 UTC, Carlin St Pierre 
wrote:
 Is it possible to get the list of usages of a template during 
 compile time?

 For example:

 class Foo
 {
 	void bar(T)(T t)
 	{

 	}
 }

 void main()
 {
 	Foo foo = new Foo;
 	foo.bar(1); // int
 	foo.bar(2f); // float
 	foo.bar("3"); // string
 }

 // pragma(msg, TemplateThatGetsTemplateUsages!(Foo.bar)) would 
 print:
 // (int, float, string)
Not without hacking the compiler.
Nov 17 2016
prev sibling parent lobo <swamp.lobo gmail.com> writes:
On Thursday, 17 November 2016 at 09:40:45 UTC, Carlin St Pierre 
wrote:
 Is it possible to get the list of usages of a template during 
 compile time?

 For example:

 class Foo
 {
 	void bar(T)(T t)
 	{

 	}
 }

 void main()
 {
 	Foo foo = new Foo;
 	foo.bar(1); // int
 	foo.bar(2f); // float
 	foo.bar("3"); // string
 }

 // pragma(msg, TemplateThatGetsTemplateUsages!(Foo.bar)) would 
 print:
 // (int, float, string)
Does this do what you want? class Foo { void bar(T)(T t) { pragma(msg, __FUNCTION__); } }
Nov 17 2016