Ranges

Jonathan M Davis jmdavisProg at gmx.com
Sat Mar 12 16:43:43 PST 2011


On Saturday 12 March 2011 16:05:37 Jonathan M Davis wrote:
> You could open an
> enhancement request for copy to treat char[] and wchar[] as arrays if
> _both_ of the arguments are of the same type.

Actually, on reflection, I'd have to say that there's not much point to that. If 
you really want to copy on array to another (rather than a range), just use the 
array copy syntax:

void main()
{
    auto i = [1, 2, 3, 4];
    auto j = [3, 4, 5, 6];
    assert(i == [1, 2, 3, 4]);
    assert(j == [3, 4, 5, 6]);

    i[] = j[];

    assert(i == [3, 4, 5, 6]);
    assert(j == [3, 4, 5, 6]);
}

copy is of benefit, because it works on generic ranges, not for copying arrays 
(arrays already allow you to do that quite nicely), so if all you're looking at 
copying is arrays, then just use the array copy syntax.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list