C++ Macro to D mixin template, delegates Please help

BLS nanali at nospam-wanadoo.fr
Fri Sep 21 04:30:20 PDT 2007


Henning Hasemann schrieb:
> Thanks for all the compliments :)
> 
> 
>> Just one question : It seems that you use template overloading, or do
>> I miss something. In other words : Can I use template overloading
>> like function overloading ?
> 
> Somehow you can do stuff like this for example:
> 
> template Foo(int n, T) {
>   // some stuff
> }
> 
> template Foo(T) {
>   // something else
> }
> 
> You can even define templates differently for different types, but
> thats called "specialisation" not overloading.
> 
> But I dont use such a thing here. What I do is defining a few templated
> structs and the structs (not instances of them, the actual type!) are
> given to MessageMap which calls the static functions.
> 
> So technically, OnClose!(foo) and OnRange!(1, 3, bar) are *types* that
> contain aliases (think of compile time references) to the methods you
> want to call.
> 
> The "mixin MessageMap!(...)" simply adds a new method to your class.
> Note that because it is run over types, the "foreach(mapping; Mappings)
> { .. }" is done at compile time, ie its body is repeated for every type
> (I called them Mapping's here), so all runtime overhead you have are
> the ifs that evaluate to false.
> 
> If you have further questions, dont hesitate to ask :)

I am afraid that will happen :-)

> 
> Henning
> 

Just to show you what I am translating :
http://www.beyondata.com/pwc.html
A really smart GUI.
Download if you like the Pretty WinApi Class, it is a small one.
(I need as GUI toolkit for my IDE project)

However, thanks to your and Regan's help I am ready to give it a go.
Many thanks ! Bjoern


More information about the Digitalmars-d-learn mailing list