www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16332] New: std.algorithm.copy uses too restricted array

https://issues.dlang.org/show_bug.cgi?id=16332

          Issue ID: 16332
           Summary: std.algorithm.copy uses too restricted array
                    specialization
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: drug2004 bk.ru

In case of array `std.algorithm.copy` uses an array specialization that assumes
that that arrays can be bitblt-ed and this assumption is false if array
contains elements that can not be bitblt-ed but can be copied by elements.
For examples, a structure with indirections with copy ctor or custom `opAssign`
can not be bitblt-ed:
```
struct Foo
{
    int[] i;
}

const(Foo)[] cfoo;
Foo[] foo;

cfoo.copy(foo); // doesn't compile because
                // 'copy' uses the array specialization:
                // foo[] = cfoo[];
```
but
```
struct Foo
{
    int[] i;

    ref Foo opAssign(const(Foo) other)
    {
        ...
    }
}

cfoo.copy(foo); // doesn't compile again because
                // `copy` again uses the same array specialization
                // foo[] = cfoo[]; <- this fails again
                // but should use:
                // foreach(idx; cfoo.length)
                //     foo[idx] = cfoo[idx];
```
That is for array `copy` should detect if it can be bitblt-ed or should be
copied by element.

--
Jul 28 2016