Code block as template argument
drug
drug2004 at bk.ru
Tue Feb 11 15:50:44 UTC 2020
On 2/11/20 2:39 PM, Виталий Фадеев wrote:
> We love small beauty code. Smaller is better. Readable is better.
How the following:
```D
TPL(OPEN, Direction.OUT,
{
AppsWindow);
state &= !OPEN;
}
);
```C
is larger and less readable than
```
TPL( OPEN, OUT,
{
delete AppsWindow
state &= !OPEN
}
)
```
Yes, this
```
void TPL(Func)(uint M, Direction D, Func func) {
if ((state & M) && (direction == D)) {
func();
}
}
```
takes a little bit more line than
```
#define TPL(M,D,CODE) if ( state & M && diraction = D ) CODE;
```
But this gives you much more abilities - for example in D this code is
processed by the compiler and the compiler gives you much more
informative errors, for example. Хотя, конечно, на вкус и цвет, товарища
нет.
More information about the Digitalmars-d
mailing list