[Issue 4977] cannot use nothrow or pure with Rebindable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 2 18:40:14 PDT 2010


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



--- Comment #2 from Jonathan M Davis <jmdavisProg at 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: -------


More information about the Digitalmars-d-bugs mailing list