|
Utility Rack
|
Utility functions for conveniently casting a pointer between types, primarily from some type T to either a char* or std::byte*.
More...

Go to the source code of this file.
Functions | |
| template<typename Dst , typename Src > | |
| const Dst * | chops::cast_ptr_to (const Src *p) noexcept |
| template<typename Dst , typename Src > | |
| Dst * | chops::cast_ptr_to (Src *p) noexcept |
Utility functions for conveniently casting a pointer between types, primarily from some type T to either a char* or std::byte*.
C++ reinterpret_cast can cast any pointer to another pointer type, but the behaviour can be undefined, depending on the access and usage. C++ guarantees that a pointer can be safely cast to void* and then to a char* (or std::byte*, which is one of the char* types), and that pointer can be cast back to the original pointer type. Casting between two unrelated types (outside of the void* and char* conversions already mentioned) results in undefined behavior (even if functionally the memory layout is the same and execution is successful on a given platform).
Both const and non-const overloads are available.
std::bit_cast function.Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)