Modify rule S6181: Fix typos (CPP-4112) (#1577)

This commit is contained in:
Marco Borgeaud 2023-02-17 12:35:10 +01:00 committed by GitHub
parent 4a54cf1b62
commit dbc0a4e295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,13 @@
``++std::bit_cast++`` is one of the standard functions working with the binary representation. Together with other bit-level functions, it is defined in the ``++<bits>++`` header introduced by {cpp}20.
``++std::bit_cast++`` is one of the standard functions working with binary representation. Together with other bit-level functions, it is defined in the ``++<bit>++`` header introduced by {cpp}20.
``++std::bit_cast++`` standardizes the diverse and sub-optimal approaches of reinterpreting a value as being of a different type of the same length preserving its binary representation.
Before {cpp}20 the correct way to reinterpret a value was a call to ``++std::memcpy++``, copying the exact binary representation from a variable of one type into a variable of another. Although canonical, the use of ``++std::memcpy++`` might still be confusing, it is verbose, and it might introduce performance overhead if the compiler does not recognize the idiom and does not remove the function call.
Before {cpp}20, the correct way to reinterpret a value was a call to ``++std::memcpy++``, copying the exact binary representation from a variable of one type into a variable of another. Although canonical, the use of ``++std::memcpy++`` might still be confusing, it is verbose, and it might introduce performance overhead if the compiler does not recognize the idiom and does not remove the function call.
In contrast, ``++std::bit_cast++`` clearly states the intent and is guaranteed to map to an optimal implementation.
In contrast, ``++std::bit_cast++`` clearly states the intent and is guaranteed to map to an optimal implementation.
This rule reports the uses of ``++std::memcpy++`` that can be replaced by ``++std::bit_cast++``.