digitalmars.D - SumRange
```d import std; struct sumrange(E){ //void* me; //TypeInfo meta; E delegate() front_; E front()=>front_(); void delegate() popFront_; void popFront()=>popFront_(); bool delegate() empty_; bool empty()=>empty_(); void opAssign(T)(ref T t){ //me=cast(void*)&t; static assert(is(typeof(t.front())==E)); front_=cast(E delegate())&t.front; popFront_=cast(void delegate())&t.popFront; empty_=cast(bool delegate())&t.empty; } } unittest{ sumrange!int foo; auto bar=iota(int(10)); foo=bar; foreach(i;foo){ i.writeln; } auto bar2=[1,2,3].map!(a=>a); foo=bar2; foreach(i;foo){ i.writeln; } auto bar3=only(1); foo=bar3; foreach(i;foo){ i.writeln; } //foo=iota(10.0);//Error: static assert: `is(double == int)` is false } ``` Using sumtype or choice to get ranges to actually work in dense metaprogramming is very very hard; this looks like it will just work. Id ship it. Maybe aim for `SumRange!(ForwardRange!int)`, `SumRange!(BidirectionalAssignable!float)` to match upstream style guide
Sep 23
On Wednesday, 24 September 2025 at 00:12:40 UTC, monkyyy wrote:Using sumtype or choice to get ranges to actually work in dense metaprogramming is very very hard; this looks like it will just work. Id ship it. Maybe aim for `SumRange!(ForwardRange!int)`, `SumRange!(BidirectionalAssignable!float)` to match upstream style guidePlease make that a DUB package.
Sep 23
On Wednesday, 24 September 2025 at 02:15:40 UTC, Kapendev wrote:On Wednesday, 24 September 2025 at 00:12:40 UTC, monkyyy wrote:Only fake anime watchers dubUsing sumtype or choice to get ranges to actually work in dense metaprogramming is very very hard; this looks like it will just work. Id ship it. Maybe aim for `SumRange!(ForwardRange!int)`, `SumRange!(BidirectionalAssignable!float)` to match upstream style guidePlease make that a DUB package.
Sep 23