On Friday, 6 September 2019 at 10:37:16 UTC, aliak wrote:
Are there any library APIs that allow this:

I just put this together. Any holes other the AA related ones?

Will it work with classes?

auto dupDeep(T)(ref T thing) {
    import std.range: ElementType;
    import std.traits: hasAliasing, Unqual, isArray;

    static if (isArray!T) {
        Unqual!(ElementType!T)[] copy;
        foreach (elem; thing) {
            copy ~= elem.dupDeep;
        }
    } else static if (hasAliasing!T) {
        Unqual!T copy;
        foreach (i, field; thing.tupleof) {
            copy.tupleof[i] = field.dupDeep;
        }
    } else {
        Unqual!T copy;
        copy = thing;
    }
    return copy;
}

Reply via email to