One of the thing I like in D
Dom Disc
dominikus at scherkl.de
Tue Oct 8 08:38:15 UTC 2024
On Monday, 7 October 2024 at 20:03:46 UTC, Boaz Ampleman wrote:
> ```d
> void main()
> {
> auto a = 0;
> auto b = 0;
> auto c = 1;
>
> auto ptr = &(c ? a : b);
> *ptr = 8;
> assert(a == 8);
> ptr = &(c ? b : a);
> *ptr = 2;
> assert(a + b == 10);
> }
> ```
>
> It's just beautiful
But why pointers?
```d
void @safe main()
{
auto a = 0;
auto b = 0;
auto c = 1;
(c ? a : b) = 8;
assert(a == 8);
(c ? b : a) = 2;
assert(a + b == 10);
}
```
More information about the Digitalmars-d
mailing list