December 23, 2010
Hello,
I've been trying to manage this on my own for like 2 days but still couldn't
do that, and because my brain just suddenly turned-off, I would ask You for
some guidance.

The thing is:
I'd like to make some kind of messaging in my application. So, there is
- interface Msg
- classes that are implementing it, i.e. MsgWindowClose
- interface Provider for message publishers, i.e. MsgProviderWindowClose
- interface Listener for message subscibers i.e. MsgListenerWindowClose
- interface Handler for message filters i.e. bool MsgHandlerWindowClose.log()
- interface Mediator for message passing between program classes, i.e.
MsgMediatorDMultiThreading() - which is using D messages btw.

Nothing related to D so far. Key thing is, that most of this Msg objects will
be really generic, so I'm building object generator, i.e
MsgProviderGen!"WindowClose":
<code>
template MsgProviderGen(string MSG, Args...) {

	const char[] MsgProviderGen = "class MsgProvider"~MSG~" : MsgProvider {"

			~"override Msg"~MSG~" getMsg() {"
				~"return new Msg"~MSG~";"
			~"}"

		~"}";

}
</code>
Which will be bigger of course.

Then, for standard and generic messages i can easily define:
<code>
private import
	msg.msg,
	msg.provider.gen,
	msg.handler.gen;

class MsgWindowClose : Msg {

}
mixin(MsgProviderGen!"WindowClose");
</code>


So far so good, but then if I'd like to add
<code>mixin("immutable uint id="~static_id~";")</code>
for each *class* (not object) I got a

PROBLEM:
Each compile-time variable has to be const, right? So I can't increment my
`static_id` each time I build a class (how many times template has generated
provider/listener of this type). This wont let me statically check if each
listener has its provider.

Surely it's not the only use of this feature, For loosen coupling, I'd wish to add function that statically returns array of Msg defined in module. It isn't an option without compile-time variables too.

Is it something about undefined module initialization?
Or maybe there is any way to overcome this problems, since I'm still new @ D
language.

Ps. How to make associative array of dynamic arrays? <code>MsgHandler[hash_t][] _handlers = new MsgHandler[hash_t][];</code> wont work.

Thanks for help,
Mariusz Gliwiński