On Tuesday, 11 August 2015 at 08:59:50 UTC, DLearner wrote:
From dlang:
Static array properties are:
...
.dup Create a dynamic array of the same size and copy the
contents of the array into it.
.idup Create a dynamic array of the same size and copy the
contents of the array into it. The copy is typed as being
immutable.
...
Dynamic array properties are:
...
.dup Create a dynamic array of the same size and copy the
contents of the array into it.
.idup Create a dynamic array of the same size and copy the
contents of the array into it. The copy is typed as being
immutable. D 2.0 only
...
<<<
The problem:
'dup' is an abbreviation of 'duplicate'.
However, for static arrays, result is not a true duplicate of
the source.
But, for dynamic arrays, result is a true duplicate.
So the same abbreviation produces two different effects.
Bugsource?
Suggested solution:
For static arrays, replace '.dup' with '.dyn' (and similarly
for 'idup').
Use of 'dyn' would also add clarity.
2 choices:
1) break people's code and documentation by renaming .dup on
static arrays
2) have 2 equivalent names for the same thing
Neither is likely to happen.
If you want it for your own code:
T[] dyn(T, size_t n)(T[n] a)
{
return a.dup;
}