src: introduce upx::ptr_reinterpret_cast
This commit is contained in:
@@ -31,6 +31,24 @@
|
||||
|
||||
namespace upx {
|
||||
|
||||
/*************************************************************************
|
||||
// misc
|
||||
**************************************************************************/
|
||||
|
||||
// a reinterpret_cast that does not trigger -Wcast-align warnings
|
||||
template <class Result, class From>
|
||||
forceinline Result ptr_reinterpret_cast(From *ptr) {
|
||||
static_assert(std::is_pointer_v<Result>);
|
||||
static_assert(!std::is_const_v<std::remove_pointer_t<Result> >); // enforce same constness
|
||||
return (Result) (void *) ptr;
|
||||
}
|
||||
template <class Result, class From>
|
||||
forceinline Result ptr_reinterpret_cast(const From *ptr) {
|
||||
static_assert(std::is_pointer_v<Result>);
|
||||
static_assert(std::is_const_v<std::remove_pointer_t<Result> >); // required
|
||||
return (Result) (const void *) ptr;
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
// type_traits
|
||||
**************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user