A template construct like using()
cc
cc at nevernet.com
Tue Apr 26 23:00:57 UTC 2022
On Tuesday, 26 April 2022 at 21:33:43 UTC, Chris Katko wrote:
> I swear I asked something like this before years ago but it
> doesn't show up in my previous forum posts.
>
> I'm looking for a construct that mimics using(var)/with(var)
```d
void draw_with(bitmap* drawb, void delegate() dg) {
set_target_bitmap(drawb);
dg();
set_target_bitmap(original_target);
}
bitmap* b;
draw_with(b, {
draw_pixel(red, 16, 16);
});
```
If your draw code doesn't depend on any scoped state you can use
`function()` instead of `delegate()` to save a GC call.
More information about the Digitalmars-d-learn
mailing list