On Friday, 16 August 2024 at 16:30:09 UTC, Jonathan M Davis wrote:
Well, you if you use dup, you're asking for a mutable array, whereas if you use idup, you're asking for an immutable array.
Yes, `idup` may be needed e.g. for overloads varying on mutability.
Whether the result of dup is then able to be implicitly converted to immutable based on whether the operation is pure depends on the element type and where the result is used.
If it can't be converted to immutable then `idup` won't work either.
So, dup may very well work in this particular case, but in the general case, you really want to be using idup if you want immutable. And in this particular example, all it would take to make the result not immutable would be to use auto instead of string.
Because `idup` exists, sure use that. But writing `immutable s = a.dup;` does the same thing.