Code block as template argument

Виталий Фадеев vital.fadeev at gmail.com
Tue Feb 11 11:10:44 UTC 2020


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 ?




More information about the Digitalmars-d mailing list