when should ranges be static

Inkrementator invalid at invalid.org
Sat Feb 15 11:47:58 UTC 2025


On Thursday, 6 February 2025 at 20:08:36 UTC, monkyyy wrote:
> I have template hell code; eventually 5 nested range calls have 
> dual context-y issues and maybe compiler bugs; adding static 
> makes those errors go away, adding static to everything makes 
> new bugs.
>
> Wack-a-mole when the compiler gets confused about context is 
> not a long term solution and for all I know, wont even be 
> stable.
>
> ---
>
>> foo is a nested function and cannot be accessed by bar
>
> When foo and bar are a top level range functions; this error is 
> nonsense, but im treating it like a dual context error because 
> it seems to act that way.
>
> ---
>
> https://github.com/crazymonkyyy/ref-algorithms/blob/master/refalgorithm.d

Wrapping foo in another delegate seems to at least compile.
```
auto split(alias F,R)(R r){
	static struct splitter{
		R r;
		auto front()=>r.takeuntil(r.findnext!(i => F(i)));
		void popFront(){r=r.findnext!(i => F(i));}
		bool empty()=>r.empty;
	}
	return splitter(r);
}
```

I put `r.findnext!(i => F(i))` instead of `r.findnext!(F)`. I 
don't understand why this works and haven't checked whether this 
actually saves allocations.d


More information about the Digitalmars-d-learn mailing list