Skip to content

Commit f33dd51

Browse files
xuhdevhsutter
andauthored
C.183: Mention bit_cast as a C++20+ solution (#2293)
* C.183: Mention bit_cast as a C++20+ solution * Remove last line The change looks good, just removing the last line as it's more documentation than guidance --------- Co-authored-by: Herb Sutter <[email protected]>
1 parent f52da2b commit f33dd51

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

CppCoreGuidelines.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9032,7 +9032,9 @@ but at least we can see that something tricky is going on.)
90329032
Unfortunately, `union`s are commonly used for type punning.
90339033
We don't consider "sometimes, it works as expected" a conclusive argument.
90349034

9035-
C++17 introduced a distinct type `std::byte` to facilitate operations on raw object representation. Use that type instead of `unsigned char` or `char` for these operations.
9035+
Modern C++ introduced `std::byte` (C++17) and `std::bit_cast` (C++20) to facilitate operations on raw object representations.
9036+
Use `reinterpret_cast` along with `std::byte` instead of `unsigned char` or `char` for these operations.
9037+
90369038

90379039
##### Enforcement
90389040

0 commit comments

Comments
 (0)