InputRange for data structure without order?

monkyyy crazymonkyyy at gmail.com
Wed Jun 4 19:53:59 UTC 2025


On Wednesday, 4 June 2025 at 19:00:57 UTC, Ali Çehreli wrote:
> On 6/4/25 4:10 AM, Monkyyy wrote:
> > On Wednesday, 4 June 2025 at 02:11:18 UTC, H. S. Teoh wrote:
> >> . But in general, containers should NOT be conflated with
> ranges. That
> >> only leads to wrong design.
> >>
> >> range should NOT mutate the container.  It should be
> regarded as
> >> something separate from the container.
> >
> > Not "general". It's a safety vs speed tradeoff. Immutable
> whatever's
> > data structure do just make allot of copies or allot of
> pointer overhead
> > and indirection.
>
> I don't understand. Like H. S. Teoh said, a range over a 
> container should not alter the container. I'm not aware of any 
> data structure where that's not the case.
>
> If a container has a way of accessing the elements (which it 
> definitely has to because otherwise it's not really a 
> container), then a light-weight range can be specified over the 
> elements.
>
> Ali

Iota should mutate the underlining data and does. Unjustifiably 
slices are in the weird limbo, the autodecoding's popFront is raw 
mutation. I think the some of the rng primitives also just 
mutate. Nullable is a range for some God-Forsaken reason, it 
would have to mutate data.

And thats just whats in phoboes rn, not even stuff Id write(op 
said he had a set and was worried about the speed).

The purist "view of data" came after, and stuff like sorting 
*absolutely shouldnt* be held to it.

Trade offs. 80% of datastructures and 90% of algorthims should be 
functional-y; but dont go full purist.



More information about the Digitalmars-d-learn mailing list