Selected elements from splitter output
Ali Çehreli
acehreli at yahoo.com
Tue May 4 22:02:11 UTC 2021
On 5/4/21 1:40 PM, Chris Piker wrote:
> I only care about columns 0, 2, 3, 4, 8, 9, 10.
That's std.range.stride.
> char[][] wanted = string_range.get( [1, 5, 7] ); // pseudo-code element
That's std.range.indexed.
import std.range;
import std.stdio;
void main() {
auto r = 10.iota.stride(2);
writeln(r);
writeln(r.indexed([1, 3]));
// Note: The above works only because 'stride' applies
// "design by introspection" (DbI) and is able to work as a
// RandomAccessRanges. Not every range can do that; so, in a more
// general case, you would have to turn your range to a
// RandomAccessRange by calling std.array.array first:
auto r2 = r.array;
// The following can work with any InputRange only after doing that.
writeln(r2.indexed([1, 3]));
}
Ali
More information about the Digitalmars-d-learn
mailing list