Value | Meaning |
---|---|
front0b00_0000_0001 | |
back0b00_0000_0010 | Ditto |
popFront0b00_0000_0100 | Ditto |
popBack0b00_0000_1000 | Ditto |
empty0b00_0001_0000 | Ditto |
save0b00_0010_0000 | Ditto |
length0b00_0100_0000 | Ditto |
opDollar0b00_1000_0000 | Ditto |
opIndex0b01_0000_0000 | Ditto |
opSlice0b10_0000_0000 | Ditto |
accessfront | back | opIndex | Ditto |
poppopFront | popBack | Ditto |
import std.algorithm.comparison : equal; import std.algorithm.iteration : map, splitter; import std.conv : to, ConvException; auto s = "12,1337z32,54,2,7,9,1z,6,8"; // The next line composition will throw when iterated // as some elements of the input do not convert to integer auto r = s.splitter(',').map!(a => to!int(a)); // Substitute 0 for cases of ConvException auto h = r.handle!(ConvException, RangePrimitive.front, (e, r) => 0); assert(h.equal([12, 0, 54, 2, 7, 9, 0, 6, 8]));
import std.algorithm.comparison : equal; import std.range : retro; import std.utf : UTFException; auto str = "hello\xFFworld"; // 0xFF is an invalid UTF-8 code unit auto handled = str.handle!(UTFException, RangePrimitive.access, (e, r) => ' '); // Replace invalid code points with spaces assert(handled.equal("hello world")); // `front` is handled, assert(handled.retro.equal("dlrow olleh")); // as well as `back`
This enum is used to select the primitives of the range to handle by the handle range wrapper. The values of the enum can be OR'd to select multiple primitives to be handled.
RangePrimitive.access is a shortcut for the access primitives; front, back and opIndex.
RangePrimitive.pop is a shortcut for the mutating primitives; popFront and popBack.