Code block as template argument
Виталий Фадеев
vital.fadeev at gmail.com
Tue Feb 11 11:14:53 UTC 2020
On Tuesday, 11 February 2020 at 11:10:44 UTC, Виталий Фадеев
wrote:
> I want template this code
>
> if ( state & INIT && diraction = IN )
> {
> Label
> text = "text"
> }
>
> if ( state & OPEN && diraction = OUT )
> {
> delete AppsWindow
> state &= !OPEN
> }
>
> to
>
> TPL( INIT, IN,
> {
> Label
> text = "text"
> }
> )
>
>
> TPL( OPEN, OUT,
> {
> delete AppsWindow
> state &= !OPEN
> }
> )
>
>
> Desctiption:
> condition: "if ( state & OPEN && diraction = OUT )"
> replace to template: "TPL( M, D )"
> pass code block as argument.
>
> Analog C-code with macros:
> #define TPL(M,D,CODE) if ( state & OPEN && diraction = OUT
> ) CODE;
> example code
> TPL( OPEN, OUT,
> {
> delete AppsWindow
> state &= !OPEN
> }
> )
>
> It possible in D ?
> How pass code block to template ?
> How to solve this problem ?
Version 2 of question. more accurate.
I want template this code
if ( state & INIT && diraction = IN )
{
Label
text = "text"
}
if ( state & OPEN && diraction = OUT )
{
delete AppsWindow
state &= !OPEN
}
to
TPL( INIT, IN,
{
Label
text = "text"
}
)
TPL( OPEN, OUT,
{
delete AppsWindow
state &= !OPEN
}
)
Desctiption:
condition: "if ( state & OPEN && diraction = OUT )"
replace to template: "TPL( M, D, CODE )"
pass code block as argument.
Analog C-code with macros:
#define TPL(M,D,CODE) if ( state & M && diraction = D ) CODE;
example code
TPL( OPEN, OUT,
{
delete AppsWindow
state &= !OPEN
}
)
It possible in D ?
How pass code block to template ?
How to solve this problem ?
More information about the Digitalmars-d
mailing list