countUntil to print all the index of a given string.

Seb seb at wilzba.ch
Sun Feb 25 02:58:33 UTC 2018


On Sunday, 25 February 2018 at 02:37:00 UTC, Jonathan M Davis 
wrote:
> If any exceptions could be thrown, then a lazy solution can't 
> be @nogc (something that's often the case with strings thanks 
> to auto-decoding and UTFExceptions), and a solution could be 
> eager without allocating if the result doesn't require any 
> allocation.

FYI -dip1008 is a thing now and part of 2.079.
See also:

https://dlang.org/changelog/pending.html#dip1008
https://run.dlang.io/is/clNX6G
https://github.com/dlang/DIPs/blob/master/DIPs/DIP1008.md


> Also, you could have a lazy range that involves a lambda that 
> allocates a closure.

Of course, or a @nogc range that allocates with malloc or eagerly 
steps through the entire range.

Anyhow I just mentioned it because it's the best form of 
automatic checking that we have (what the OP was asking for) and 
in many cases when an algorithm can't be @nogc it does allocate 
somewhere which is a red flag.


More information about the Digitalmars-d-learn mailing list