Limitations of C++ range proposal
Ali Çehreli
acehreli at yahoo.com
Mon Sep 16 21:47:08 UTC 2019
On 09/16/2019 12:53 PM, jmh530 wrote:
> I ran across this blog post on limitations of the C++ range proposal [1]
> and wrote up a simple D version in virtually no time.
I had fun implementing the following version, which should not create
any array:
import std.stdio;
import std.range;
auto interspersed(R, D)(R r, D delim) {
struct MyRoundRobin {
bool doDelim = false;
auto empty() {
return r.empty;
}
auto front() {
return (doDelim ? delim : r.front);
}
auto popFront() {
if (!doDelim) {
r.popFront();
}
doDelim = !doDelim;
}
}
return MyRoundRobin();
}
void main(){
auto r = 10.iota.interspersed(42);
writefln("%(%s %)", r);
}
std.range.roundRobin came close but it does not support 'StoppingPolicy'
like 'zip' and 'lockstep' do.
Ali
P.S. I ran into a checked format string issue and created the following
bug report:
https://issues.dlang.org/show_bug.cgi?id=20218
More information about the Digitalmars-d
mailing list