Hello. How to cast template struct to itself?

struct vec(string S,T=double)
{
    T[S.length] data;
    auto opCast(string K,E)()
        if( S.length == K.length &&
             is( T : E ) )
    {
        vec!(K,E) ret;
        foreach( i, ref m; ret.data )
            m = data[i];
        return ret;
    }
}

unittest
{
    alias vec!"xyz" dvec3;
    alias vec!("rbg",float) fcol3;
    auto a = dvec3([1,2,3]);
    auto b = fcol3();
    b = a; #1
    assert( b.data == [1,2,3] );
}

#1 Error: cannot implicitly convert expression (a)
of type vec!("xyz") to vec!("rbg",float)

Reply via email to