mirror of
https://github.com/dlang/phobos.git
synced 2025-04-26 13:10:35 +03:00

* Add std.conv.bitCast This helper function is a more readable alternative to the traditional pointer-cast-based syntax for reinterpreting casts. The name bitCast is used for this operation in several other languages, including C++ [1], Swift [2], C# [3], Zig [4], and LLVM IR [5]. [1] https://en.cppreference.com/w/cpp/numeric/bit_cast [2] https://developer.apple.com/documentation/swift/unsafebitcast(_:to:) [3] https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.bitcast [4] https://ziglang.org/documentation/0.10.0/#bitCast [5] https://llvm.org/docs/LangRef.html#bitcast-to-instruction * Add changelog entry for std.conv.bitCast
14 lines
282 B
Text
14 lines
282 B
Text
Added `std.conv.bitCast`
|
|
|
|
This convenience function allows reinterpreting casts to be written in a more
|
|
readable way.
|
|
|
|
---
|
|
uint n = 0xDEADBEEF;
|
|
|
|
// Before
|
|
writeln("Bytes of n are: ", *cast(const ubyte[4]*) &n);
|
|
|
|
// After
|
|
writeln("Bytes of n are: ", n.bitCast!(const ubyte[4]));
|
|
---
|