Alternative Possibility - Implicit with

zjh fqbqrr at 163.com
Sun Nov 20 02:24:25 UTC 2022


On Sunday, 20 November 2022 at 01:26:25 UTC, H. S. Teoh wrote:

> Currently, `with` supports only one identifier; this could be 
> enhanced to allow multiple identifiers so that you don't need 
> to have 3-4 nested blocks just to have 3-4 implicit identifiers:
>
> 	enum MyLongEnum { ... }
> 	class MyClass { ... }
> 	struct MyStruct { ... }
> 	with (MyLongEnum, MyClass, MyStruct) {
> 		... // use members of all 3 without needing to spell them out 
> every time
> 	}
>


It's a little different. I don't want to wrap it with a `{}`.
I hope that the entire `function scope`can be used directly 
without adding a `prefix`.
In my opinion, this is simpler,because most of the time `enum` 
are continuous. I can put `enumerater handler` functions into a 
`vector(or array)(C++)`, but still add `prefix`, which is a bit 
troublesome.
It is very convenient if you do not add a prefix to the entire 
`function scope`.
For example:

```d
enum longName{A,B,C};
struct longName2{
     static int g(){
         ...
     }
};
void f(){
     using longName;
     using gg=function<int(int)>;//C++
     gg[] fl;//gg
     fl[A],fl[B]...
     ...directly using A,B,C like this...;
}

void k(){
     using longName2;//struct/class
     ...directly using static g...
}

```




More information about the Digitalmars-d mailing list