[Issue 20112] __vector casts don't do type conversions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 9 04:44:33 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20112

Iain Buclaw <ibuclaw at gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw at gdcproject.org

--- Comment #1 from Iain Buclaw <ibuclaw at gdcproject.org> ---
That's because `__vector(int[4]) i = cast(__vector(int[4])) f;` is a
reinterpret cast.

Semantically, this can only be done by unrolling the assignment, but probably
easier to do this in phobos std.conv instead.

private T to(T, S)(S value)
{
    alias E = typeof(T.init[0]);
    T res = void;
    static foreach (i; 0 .. S.length)
        res[i] = cast(E)value[i];
    return res;
}

void main() {
    import std.stdio;
    __vector(float[4]) f = [3, 2, 1, 0];
    __vector(int[4]) i = to!(__vector(int[4]) f;
    writeln(i[0]);
}

--


More information about the Digitalmars-d-bugs mailing list