I'm trying to revamp array() to follow Bearophile's very good suggestion of letting any foreachable object be convertible to an array even if it's opApply-based, not a range. My efforts have been blocked by this cryptic piece of code:

        foreach (ref e; result)
        {
            // hacky
            static if (is(typeof(&e.opAssign)))
            {
                // this should be in-place construction
                new(&e) E(r.front);
            }
            else
            {
                e = r.front;
            }
            r.popFront;
        }

It took me awhile to even wrap my head around what the point of that code is. First of all, why are we bypassing opAssign? Secondly, what if the E doesn't have a constructor that takes only another E as an argument?
_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to