Array of const objects with indirections and std.algorithm.copy

drug via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 28 00:30:33 PDT 2016


I see. I'll try to rephrase my question to be clear. We have:
```
struct Foo
{
	int i;
	float f;
}

int main()
{
	const(Foo)[] cfoo = [Foo(1, 0.5), Foo(2, 0.75)];
	Foo[] foo;

	cfoo.copy(foo); // it works, constness no matter here because Foo is 
value type
}
```
but if Foo contains indirections it won't be a value type anymore and 
`copy` doesn't work. It's right and expected. Then I define `opAssign` 
to accept a const instance of `Foo` and I expect that `copy` should work 
because `Foo` (with indirections) now can be safely copied using 
`opAssign`. But it doesn't work just because current implementaion of 
`copy` assumes that if its arguments are array then it can be low-level 
copied. But `cfoo` is array of element that can't be bitblt-ed and 
should be copied by element. `copy` does by element copying for ranges, 
but not for arrays.
Am I wrong or copy array specialization should be extended to support 
arrays that require by element copying?


More information about the Digitalmars-d-learn mailing list