Template namespaces - Obsolete?

Michel Fortin michel.fortin at michelf.com
Wed Sep 19 13:51:02 PDT 2007


On 2007-09-19 15:23:36 -0400, "Janice Caron" <caron800 at googlemail.com> said:

> Is there any need, any more, for the old fashioned
> 
> template t(T)
> {
>     int f();
>     int g();
> }

I haven't seen it yet, but templates are very powerful when combined 
with static if. You can only do that the "old fashioned" way.

This code is from the D/Objective-C bridge I released yesterday:

/**
 * Number of arguments in method name. This simply count the number of
 * colon character within the string.
 */
template methodArgumentCount(char[] name) {
	static if (name.length == 0) {
		const uint methodArgumentCount = 0;
	} else static if (name[0] == ':') {
		const uint methodArgumentCount = 1 + methodArgumentCount!(name[1..$]);
	} else {
		const uint methodArgumentCount = methodArgumentCount!(name[1..$]);
	}
}


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list