Shared, ref, arrays, and reserve template instantiation

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Sep 13 05:58:48 UTC 2018


On Wednesday, September 12, 2018 9:42:19 PM MDT James Blachly via 
Digitalmars-d-learn wrote:
> Neia is right that I tried to cast as in the second case ( but
> without UFCS -- reserve( cast(int[]), N); ).  As an aside, what
> is going on behind the scenes with the compiler when casting away
> a property? I did not think cast operations copied data, so was
> surprised that a cast value is not an lvalue.

Well, you basically get a temporary variable when you cast an object, and
those are rvalues. And while casting with regards to type qualifiers such as
const or shared, you're not actually changing the data, plenty of other
casts do - e.g. float and long don't even have the same size, but you can
cast from one to the other. So, even in principle, only some casts could
result in lvalues even if we wanted them to.

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list