-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27c1b07
commit 5838f50
Showing
5 changed files
with
34 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <cstring> | ||
#include <array> | ||
#include <memory> | ||
#include <new> | ||
|
||
/** | ||
* @brief Safely convert one type to another without UB. | ||
* This is produces identical assembly to reinterpret_cast. | ||
* | ||
* @param ptr Input pointer type | ||
* @return Converted pointer type | ||
* | ||
* @tparam IN source type | ||
* @tparam OUT destination type | ||
* | ||
* This is essentially std::start_lifetime_as(), without | ||
* the requirement for C++23. | ||
* | ||
* @note Based on code by Krystian Stasiowski | ||
* (https://github.com/sdkrystian) | ||
*/ | ||
template<typename IN, typename OUT> OUT* convert_to(IN* ptr) | ||
{ | ||
return std::launder(static_cast<OUT*>(std::memmove(ptr, ptr, sizeof(OUT)))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,3 +75,4 @@ | |
#include <dpp/timed_listener.h> | ||
#include <dpp/collector.h> | ||
#include <dpp/bignum.h> | ||
#include <dpp/convert_to.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters