If you look at the struct, it uses the type U in, among others, the union.

The only place I could see U referenced is in the first static if, but I cannot recreate this behavior:
void main() {
    static if(is(int X == const(U), U))
    {
    }
    else
    {
        static assert(is(typeof(U))); // false, U not defined
    }
}


And std.typecons.Rebindable:

template Rebindable(T) if (is(T == class) || is(T == interface) || isArray!(T))
{
    static if (!is(T X == const(U), U) && !is(T X == immutable(U), U))
    {
        alias T Rebindable;
    }
    else static if (isArray!(T))
    {
        alias const(ElementType!(T))[] Rebindable;
    }
    else
    {
        struct Rebindable
        {
            private union
            {
                T original;
                U stripped;
            }
            void opAssign(T another) pure nothrow
            {
                stripped = cast(U) another;
            }
            void opAssign(Rebindable another) pure nothrow
            {
                stripped = another.stripped;
            }
            static if (is(T == const U))
            {
                // safely assign immutable to const
void opAssign(Rebindable!(immutable U) another) pure nothrow
                {
                    stripped = another.stripped;
                }
            }

            this(T initializer) pure nothrow
            {
                opAssign(initializer);
            }

            @property ref T get() pure nothrow
            {
                return original;
            }
            @property ref const(T) get() const pure nothrow
            {
                return original;
            }

            alias get this;
        }
    }
}

Reply via email to