chunkBy array at compile time

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Dec 19 18:30:34 UTC 2018


On Wed, Dec 19, 2018 at 01:19:28PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote:
> On 12/19/18 12:20 PM, H. S. Teoh wrote:
[...]
> > It was originally a simple wrapper when I first submitted it, but
> > Andrei requested to use RefCounted in order to work around the
> > subrange traversal problem. I.e., in the original implementation,
> > the underlying range traversed twice, once when each subrange is
> > consumed, and once when you call popFront on the outer range. Having
> > RefCounted allows us to retain a reference to the original range so
> > that subranges will also advance the underlying range as seen by the
> > outer range, thereby eliminating calling popFront on the underlying
> > range twice per element.
> 
> I see, that does pose an issue, especially if you aren't traversing it
> in order. Communicating back to the "outer" range where the traversal
> should stop requires having a reference to it in the subrange.
> 
> However, in terms of a random-access range, or even an array, it
> should be pretty straightforward to... oh wait, these are narrow
> strings. nevermind.
[...]

For CTFE, though, we don't really care about calling popFront twice, so
I surmise that we should be able to just use the original non-RefCounted
implementation. It's not hard, just take out the bits where the
subranges communicate with the outer range, and just have each subrange
carry its own instance of the underlying range.  It will incur some CTFE
performance hit, but that's better than not being CTFE-able at all.


T

-- 
"The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts." -- Bertrand Russell. "How come he didn't put 'I think' at the end of it?" -- Anonymous


More information about the Digitalmars-d-learn mailing list