[Issue 16332] std.algorithm.copy uses too restricted array specialization

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 28 18:56:52 UTC 2023


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

Nick Treleaven <nick at geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nick at geany.org

--- Comment #1 from Nick Treleaven <nick at geany.org> ---
Complete example:

import std.algorithm : copy;

struct Foo
{
        int[] i;

        void opAssign(const(Foo) other)
        {
                i = other.i.dup;
        }
}

void main()
{
        const(Foo)[] cfoo;
        foreach (i; 1 .. 4)
                cfoo ~= Foo([i]);
        Foo[] foo = new Foo[](3);
        //cfoo.copy(foo); // NG, should be equivalent to:
        foreach(idx; 0 .. cfoo.length)
                foo[idx] = cfoo[idx];
        assert(foo == cfoo);
}

--


More information about the Digitalmars-d-bugs mailing list