C++ Macro to D mixin template, delegates Please help
Regan Heath
regan at netmail.co.nz
Thu Sep 20 07:55:12 PDT 2007
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
More information about the Digitalmars-d-learn
mailing list