http://d.puremagic.com/issues/show_bug.cgi?id=4977



--- Comment #2 from Jonathan M Davis <jmdavisp...@gmx.com> 2010-10-02 18:39:56 
PDT ---
Here's a first attempt at a solution:

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) nothrow
            {
                stripped = cast(U) another;
            }

            void opAssign(Rebindable another) nothrow
            {
                stripped = another.stripped;
            }

            static if (is(T == const U))
            {
                // safely assign immutable to const
                void opAssign(Rebindable!(immutable U) another) nothrow
                {
                    stripped = another.stripped;
                }
            }

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

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

            T opDot() pure nothrow
            {
                return original;
            }

            T opDot() const pure nothrow
            {
                return original;
            }
        }
    }
}


With the current purity rules, I can't make opAssign() pure. It complains about
assigning to const. I don't know whether or nat that will be fixed with the
relaxed purity rules suggested by Don.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to