Currently, it is clumsy to change the type of an Element in a pipeline, as a map algorithm is needed. This algorithm does that in one simple operation:
a.b.reinterpret!T.c.d ...
It "paints" the Element type E of its input range to a new type T and presents an input range with the new type. The original and new types must be the same size, or an assert happens. Painting does not change the bits. (Hence this is unsafe when painting an int into a pointer.)
reinterpret should be lazy, pure, @nogc and nothrow.
CTFE has limited support for painting, such as painting float <=> int, the implementation must ensure that CTFE is working on it.
Comment #1 by monarchdodra — 2014-10-09T08:11:07Z
Sounds like the first step here would be to have an actual (safe/verified) reinterpretCast ?
Comment #2 by greensunny12 — 2018-02-10T19:57:40Z
> Currently, it is clumsy to change the type of an Element in a pipeline
Well, the status quo for whole elements
a.b.pipe!(a => cast(T)).c.d
And for elements:
a.b.map!(a => cast(T)).c.d
Or is this just a request to generalize std.exception.assumeUnique into assume!XYZ, but being @safe for all its generalizations?
Comment #3 by robert.schadek — 2024-12-01T16:22:39Z