ternary op assign
monkyyy
crazymonkyyy at gmail.com
Thu May 2 20:28:19 UTC 2024
On Thursday, 2 May 2024 at 18:17:12 UTC, Stefan Koch wrote:
> On Thursday, 2 May 2024 at 17:42:28 UTC, monkyyy wrote:
>> `foo?=bar:baz` is rewritten as `foo.opOpAssign!("?:")(bar,baz)`
>>
>> `foo[i]?=bar:baz` opIndexOpAssign
>>
>> for basic types it acts as `foo=(bool)bar?foo:(typeof(foo))baz`
>
> I find this syntax confusing, I would interpret that as:
>
> `foo[i] = (foo[i] ? bar : baz);`
often the statement you want to write is a=condition?b:a which
repeats a, the way to simplify (and prevent int promtion issues)
is with the += family of statements; but there isnt a clear one
for if(cond)a=b
Simd(/waterfalled code) has to do bit mask tricks, and I think
you could wrap that up in a data structure with the opslice as
recursive templates for opindex logic
```d
a/=4;
b+=a;
if(a>b)a=b;
---
a[0..4]/=4;
b[0..4]+=a[0..4];
????
```
More information about the dip.ideas
mailing list