www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Partial specialisation: howto?

reply div0 <div0 users.sourceforge.net> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Everybody,

Please have a look at the appended sucky code.

Obv. the createHandlerCode function is a pain in the back side for
extending this system; I want multiple different partially specialised
implementations.

So whats the syntax for doing partial specialisation?

Damed if I can work it out.

==================

enum EHandlerType {
	eMsgRangeHdlr,
	eMsgHdlr,
	eCmdIdHdlr
}

template createHandlerCode(T ...) {
	string format() {
		static if(T[0]._type == EHandlerType.eMsgRangeHdlr)
			return createMessageRangeHandler!(T).format();
		else static if(T[0]._type == EHandlerType.eMsgHdlr)
			return createMessageHandler!(T).format();
		else static if(T[0]._type == EHandlerType.eCmdIdHdlr)
			return createCommandIdHandler!(T).format();
		else
			static assert(false, "handler type not handled");
	}
}

struct msgRangeHdlr(uint msgIdFirst, uint msgIdLast, string
responseMethod) {
	invariant EHandlerType	_type = EHandlerType.eMsgRangeHdlr;
	invariant string	_msgIdFirst = std.metastrings.ToString!(msgIdFirst);
	invariant string	_msgIdLast = std.metastrings.ToString!(msgIdLast);
	invariant string 	_responseMethod = responseMethod;
}

struct msgHdlr(uint msgId, string responseMethod) {
	invariant EHandlerType	_type = EHandlerType.eMsgHdlr;
	invariant string	_msgId = std.metastrings.ToString!(msgId);
	invariant string 	_responseMethod = responseMethod;
}

struct cmdIdHdlr(uint cmdId, string responseMethod) {
	invariant EHandlerType	_type = EHandlerType.eCmdIdHdlr;
	invariant string	_cmdId = std.metastrings.ToString!(cmdId);
	invariant string 	_responseMethod = responseMethod;
}


- --
My enormous talent is exceeded only by my outrageous laziness.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFKD0ElT9LetA9XoXwRAi+pAKCNkTtLSjT9l7cpqor6btDvLu9STQCff4Th
FzvQZ1gxLfUEGq9PFt4Kr+Q=
=WQKw
-----END PGP SIGNATURE-----
May 16 2009
parent reply "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
div0 wrote:
 Hi Everybody,

Greetings. While I am not able to help with your problem, I would like to point you to digitalmars.D.learn, which is for questions about how the language works. digitalmars.D.announce is for announcements. -- Simen
May 16 2009
parent div0 <div0 users.sourceforge.net> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Simen Kjaeraas wrote:
 div0 wrote:
 Hi Everybody,

Greetings. While I am not able to help with your problem, I would like to point you to digitalmars.D.learn, which is for questions about how the language works. digitalmars.D.announce is for announcements. -- Simen

balls. sry. - -- My enormous talent is exceeded only by my outrageous laziness. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFKD1scT9LetA9XoXwRAovsAJ4zBzdHYU54KWcfsDxRCUNHJhijNQCghcY5 WwQXA5+6ibiSzaTcda6qYe0= =q+co -----END PGP SIGNATURE-----
May 16 2009