all: various cleanups
This commit is contained in:
+14
-18
@@ -31,24 +31,6 @@
|
||||
|
||||
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
|
||||
**************************************************************************/
|
||||
@@ -81,6 +63,20 @@ struct UnsignedSizeOf {
|
||||
static constexpr unsigned value = unsigned(Size);
|
||||
};
|
||||
|
||||
// a reinterpret_cast that does not trigger -Wcast-align warnings
|
||||
template <class Result, class From>
|
||||
forceinline Result ptr_reinterpret_cast(From *ptr) noexcept {
|
||||
static_assert(std::is_pointer_v<Result>);
|
||||
static_assert(!std::is_const_v<std::remove_pointer_t<Result> >); // enforce same constness
|
||||
return reinterpret_cast<Result>(reinterpret_cast<void *>(ptr));
|
||||
}
|
||||
template <class Result, class From>
|
||||
forceinline Result ptr_reinterpret_cast(const From *ptr) noexcept {
|
||||
static_assert(std::is_pointer_v<Result>);
|
||||
static_assert(std::is_const_v<std::remove_pointer_t<Result> >); // required
|
||||
return reinterpret_cast<Result>(reinterpret_cast<const void *>(ptr));
|
||||
}
|
||||
|
||||
class noncopyable {
|
||||
protected:
|
||||
forceinline constexpr noncopyable() noexcept {}
|
||||
|
||||
+6
-6
@@ -130,15 +130,15 @@ using XSPAN_NAMESPACE_NAME::raw_index_bytes; // overloaded for all classes
|
||||
|
||||
// helper for implicit pointer conversions and MemBuffer overloads
|
||||
template <class R, class T>
|
||||
inline R *xspan_make_helper__(R * /*dummy*/, T *first) may_throw {
|
||||
inline R *xspan_make_helper__(T *first) noexcept {
|
||||
return first; // IMPORTANT: no cast here to detect bad usage
|
||||
}
|
||||
template <class R>
|
||||
inline R *xspan_make_helper__(R * /*dummy*/, std::nullptr_t /*first*/) noexcept {
|
||||
inline R *xspan_make_helper__(std::nullptr_t /*first*/) noexcept {
|
||||
return nullptr;
|
||||
}
|
||||
template <class R>
|
||||
inline R *xspan_make_helper__(R * /*dummy*/, MemBuffer &mb) noexcept {
|
||||
inline R *xspan_make_helper__(MemBuffer &mb) noexcept {
|
||||
return (R *) membuffer_get_void_ptr(mb);
|
||||
}
|
||||
|
||||
@@ -148,9 +148,9 @@ inline R *xspan_make_helper__(R * /*dummy*/, MemBuffer &mb) noexcept {
|
||||
#define XSPAN_S(type) type *
|
||||
|
||||
// create a value
|
||||
#define XSPAN_0_MAKE(type, first, ...) (xspan_make_helper__((type *) nullptr, (first)))
|
||||
#define XSPAN_P_MAKE(type, first, ...) (xspan_make_helper__((type *) nullptr, (first)))
|
||||
#define XSPAN_S_MAKE(type, first, ...) (xspan_make_helper__((type *) nullptr, (first)))
|
||||
#define XSPAN_0_MAKE(type, first, ...) (xspan_make_helper__<type>((first)))
|
||||
#define XSPAN_P_MAKE(type, first, ...) (xspan_make_helper__<type>((first)))
|
||||
#define XSPAN_S_MAKE(type, first, ...) (xspan_make_helper__<type>((first)))
|
||||
|
||||
// define a variable
|
||||
#define XSPAN_0_VAR(type, var, first, ...) type *var = XSPAN_0_MAKE(type, (first))
|
||||
|
||||
Reference in New Issue
Block a user