Re: A template construct like using()

2022-04-27 Thread user1234 via Digitalmars-d-learn
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 bitmap* b; draw_with(b) { draw_pixel(red, 16, 16);

Re: A template construct like using()

2022-04-26 Thread Adam Ruppe via Digitalmars-d-learn
On Tuesday, 26 April 2022 at 23:00:57 UTC, cc wrote: If your draw code doesn't depend on any scoped state you can use `function()` instead of `delegate()` to save a GC call. `scope delegate` also works here and just reuses the stack.

Re: A template construct like using()

2022-04-26 Thread cc via Digitalmars-d-learn
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) {

Re: A template construct like using()

2022-04-26 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 26, 2022 at 09:33:43PM +, Chris Katko via Digitalmars-d-learn wrote: [...] > I'm looking for a construct that mimics using(var)/with(var) > > D > bitmap* b; > > draw_with(b) > { > draw_pixel(red, 16, 16); //draw red pixel to bitmap b (b is implied above) > } > >

A template construct like using()

2022-04-26 Thread Chris Katko via Digitalmars-d-learn
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 bitmap* b; draw_with(b) { draw_pixel(red, 16, 16); //draw red pixel to bitmap b (b is implied above) } But