If I want randInPlace to take value arguments (such as structs) by reference and reference types (classes) as normal is this

/** Generate Random Contents in $(D x).
 */
auto ref randInPlace(T)(auto ref T x) @safe /* nothrow */ if (isIterable!T)
{
    foreach (ref elt; x)
    {
        import std.range: ElementType;
        static if (isInputRange!(ElementType!T))
            elt[].randInPlace;
        else
            elt.randInPlace;
    }
    return x;
}

the way to do it or does

    auto ref T x

evaluate to unnecessary

    ref Class x

?

And isIterable the recommended way to do it?

And how does this compare to using x[].randInPlace() when x is a static array? Does x[] create unnecessary GC-heap activity in this case?

I'm wondering because (auto ref T x) is just used in two places in std.algorithm and std.range in Phobos. Is this a relatively new enhancement?

Reply via email to