A couple of extensions to `with` that would be worthwhile

Salih Dincer salihdb at hotmail.com
Wed Oct 13 13:32:09 UTC 2021

On Wednesday, 13 October 2021 at 11:13:32 UTC, Andrei 
Alexandrescu wrote:
> It's a tail wagging the proverbial dog. Clearly we could do 
> with better ways. We can improve the `with` statement as 
> follows:

I prefer with() while using the arsd.simpledisplay because it's 
needed a scope.

However, when you use double with(), an issue to come up! 
Compiled as follows, my only solution is:

Painter window;
with(Color) window = new Painter("AxialPCB", black, gray, red);
The new ideas are great about with() like the same inline import! 
If I used this way, it can't access it from the outside:

with(new Painter("AxialPCB", Color.black, Color.gray, Color.red) 
{ //*/ }

More information about the Digitalmars-d mailing list