Splitting Ranges using Lambda Predicates

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 11 06:58:39 PDT 2014


On 06/11/14 15:44, Artur Skawina wrote:
> If, instead, you create a string-specific 'countUntil' that returns
> a type that holds both the byte and code-point counts and implicitly
> converts to the latter, then you can have a 'takeExactly' overload
> that uses the extra info to avoid the unnecessary decoding and is able
> to directly return slices. The overhead is minimal; one extra integer
> that's passed around, and often completely eliminated by function inlining.
> But now you don't need to write a string-specific version of every
> algorithm. (Of course this description is slightly oversimplified)

Well, for safety, you'd most likely want to pass around the range too
(ie string slice, or just the pointer as the min-length is implied);
so it's two size_ts, not one. Still, the overhead is tiny and the
advantage of not having to special-case for strings everywhere is worth
it.

artur



More information about the Digitalmars-d-learn mailing list