C++ Macro to D mixin template, delegates Please help
BLS
nanali at nospam-wanadoo.fr
Thu Sep 20 08:45:01 PDT 2007
Regan Heath schrieb:
> BLS wrote:
>> template ON_WM_CLOSE(D) (D delegate() dg)
>> {
>> if (uID == WM_CLOSE)
>> {
>> lResult = dg();
>> return lResult;
>> }
>> }
>
> This seems to be mixing template syntax (using "template") with template
> function syntax (using "(D)(D delegate() dg)". I don't think you want a
> template function so, rather something like:
>
> template ON_WM_CLOSE(alias D)
> {
> if (uID == WM_CLOSE)
> {
> lResult = D();
> return lResult;
> }
> }
>
> (see the duffs_device example here
> http://www.digitalmars.com/d/template-mixin.html)
>
> However this wont work because a template body can only contain
> 'declarations' which means;
>
> Declaration:
> typedef Decl
> alias Decl
> Decl
>
> Decl:
> StorageClasses Decl
> BasicType Declarators ;
> BasicType Declarator FunctionBody
> AutoDeclaration
>
> So, you can put typedefs, aliases, variables and functions in a
> template, but, what you can't do is put an "if" statement in there. So,
> templates and mixins in D just can't achieve the same effect as the
> C/C++ define macro can.
>
> The planned/propsed D macro feature however, that should do what you
> want I reckon.
>
> Regan
NOOOOOOOOOOoooooooo, Shi* !
So I guess
template TFoo(D)
{
alias D delegate() dg
}
is also not allowed...
Hell, there should be a way to translate such a simple C++ macro without
without having so much trouble!!!
I can not imagine that it is impossible. Probabely there exist a
workaround. have to look at the Tango Signal/Slot implementation.. Imean
they 've managed it.
However, thanks Regan
Bjoern
More information about the Digitalmars-d-learn
mailing list