Partial specialisation: howto? (in the right news group this time. *sigh*)

div0 div0 at users.sourceforge.net
Sat May 16 17:34:05 PDT 2009


-----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

iD8DBQFKD1t9T9LetA9XoXwRAgKDAJ9BFJ+d5qLpPSjZn5SN9C0g1hh6HgCgrFWr
c5752+efFTIYG9/2pY4Vp5Y=
=W6lL
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list