rectifiedIndexOf()

Quirin Schroll qs.il.paperinik at gmail.com
Sat May 6 16:39:13 UTC 2023


On Friday, 5 May 2023 at 00:19:01 UTC, Salih Dincer wrote:
> It has a traditional very beautiful function: indexOf() but it 
> has an important problem: returns -1 when it can't find 'c'...

That is bad design. It should return an optional type or 
something like that, but D doesn’t have those. C++ has a lot of 
similar functions and I guess that was one reason why C++17 
introduced an *init-statment* to `if`. D could do the same.

```d
if (auto index = arr.indexOf('c'); index >= 0) …
```


More information about the Digitalmars-d mailing list