Question

As far I know maps in D have value semantics.

If so why does the second line in this example fail

const(uint[ubyte]) x;
uint[ubyte] y = x;

as

Error: cannot implicitly convert expression (x) of type const(uint[ubyte]) to uint[ubyte]

when both the key and value also have value semantics?

Était-ce utile?

La solution

As far I know maps in D have value semantics.

D associative arrays are reference types.

Internally, they are represented as a pointer to an implementation-defined data structure. (Note that if the AA is null, it does not act like a reference type, as adding the first member will instantiate it.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top