braceless with statements
Ogi
ogion.art at gmail.com
Sun Nov 14 15:45:13 UTC 2021
On Saturday, 13 November 2021 at 14:42:55 UTC, Steven
Schveighoffer wrote:
> I don't really understand the question. What is the confusion
> you are having?
Braces and indentations keep things sane:
```D
struct S { int x; }
S s;
with (s) {
/*
lots of code here
*/
x = 42; //is this s.x? The answer is always yes.
}
```
Now with `with:`:
```D
struct S { int x; }
S s;
with (s):
/*
lots of code here
*/
x = 42; //is this s.x? Depends on the code above.
```
“Lots of code” can contain anything, including something like
this:
```D
struct X {
void x(int i) {}
}
with (X()):
```
In this case `x` isn’t even a variable, it’s a function! But it
would still compile.
More information about the Digitalmars-d
mailing list