On 10/25/2015 08:31 PM, Andrei Alexandrescu wrote:
On 10/23/2015 07:21 PM, bigsandwich wrote:
On Friday, 23 October 2015 at 17:44:55 UTC, deadalnix wrote:
On Friday, 23 October 2015 at 11:03:37 UTC, Andrei Alexandrescu wrote:
[...]

Sure. We have a problem when it come to collection in the fact that
type qualifier do not turtle down as one would expect.

[...]

Its not just type qualifiers. Containers of derived types have the same
problem.  This is also a problem in C++.

This is something easy to live with. In fact, mutable containers are not
supposed to even convert to containers of base objects. -- Andrei


This is true for containers with reference semantics, but not for containers with value semantics.

This compiles (D code):

class A{}
class B: A{}

void main(){
    A[2] a;
    B[2] b;
    a=b;
}

This does not compile (C++ code):

class A{};
class B: A{};

int main(){
    vector<A*> a;
    vector<B*> b;
    a=b;
}

However, the conversion would be safe. For persistent and COW containers, the copy would even be fast.

Reply via email to