H. S. Teoh:

Which cases don't work?

Example: in a nothrow function. Unless you catch the exception locally.

To solve this in Bugzilla I have proposed a nothrow function maybeTo that returns a Nullable!T:

https://d.puremagic.com/issues/show_bug.cgi?id=6840

Also a cast is faster and lighter than to! so in some cases it's needed.


This issue will (hopefully?) be addressed when Andrei finalizes his allocators, perhaps?

Andrei allocators are very nice, and they help, but I think they can't replace the C allocation functions in every case.


I think to! can probably be extended to perform this conversion.

It's not so simple, there are some constraints.


Using a union here is not a good idea, because the results depend on the endianness of the machine! It's better to
just use (a & 0xFFFF) or (a >> 16) instead.

Right.


This is inherently unsafe, since it risks silent truncation of very large arrays.

In some cases you can assume to not have huge arrays. And you can even test the hugeness of the length before the cast or inside the function precondition.

Bye,
bearophile

Reply via email to