On Wednesday, 20 April 2016 at 12:32:48 UTC, Tofu Ninja wrote:
Is there a way to shallow copy an object when the type is known? I cant seem to figure out if there is a standard way. I can't just implement a copy function for the class, I need a generic solution.

extern (C) Object _d_newclass(TypeInfo_Class ci);

Object dup(Object obj)
{
    if (obj is null)
        return null;
    ClassInfo ci = obj.classinfo;
    size_t start = Object.classinfo.init.length;
    size_t end = ci.init.length;
    Object clone = _d_newclass(ci);
(cast(void*)clone)[start .. end] = (cast(void*)obj)[start .. end];
    return clone;
}

Reply via email to