Please improve the with statement by allowing initialisation

monkyyy crazymonkyyy at gmail.com
Wed Mar 12 19:25:23 UTC 2025


On Wednesday, 12 March 2025 at 18:55:45 UTC, Dejan Lekic wrote:
> This is what we currently _have_ to do in D:
>
> This would work because all Window methods return this. We do 
> not always have luxury of being able to change the library we 
> use, especially make such a drastic change so that all methods 
> return this

```d
struct window{
     void settitle(string){}
     void setsize(int,int){}
}
auto fluantize(T)(){
     struct flaunt{
         T t;
         typeof(this) opDispatch(string __s,A...)(A args){
             mixin("t."~__s)(args);
             return this;
     }}
     return flaunt();
}
unittest{
     auto win= fluantize!(window)
		.settitle("foo")
		.setsize(1,2);
}
```

this is bad but you dont "have to" or "change the lib"


More information about the Digitalmars-d mailing list