mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-15 03:27:49 +01:00
util: faster constexpr offsetof calc, at the cost of standards compliance
This commit is contained in:
parent
a6e3a93c07
commit
b8072b1398
@ -23,6 +23,10 @@ namespace ams::util {
|
||||
|
||||
namespace impl {
|
||||
|
||||
#define AMS_UTIL_OFFSET_OF_STANDARD_COMPLIANT 0
|
||||
|
||||
#if AMS_UTIL_OFFSET_OF_STANDARD_COMPLIANT
|
||||
|
||||
template<size_t MaxDepth>
|
||||
struct OffsetOfUnionHolder {
|
||||
template<typename ParentType, typename MemberType, size_t Offset>
|
||||
@ -101,6 +105,20 @@ namespace ams::util {
|
||||
}
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
template<typename ParentType, typename MemberType>
|
||||
struct OffsetOfCalculator {
|
||||
static constexpr std::ptrdiff_t OffsetOf(MemberType ParentType::*member) {
|
||||
constexpr TYPED_STORAGE(ParentType) Holder = {};
|
||||
const auto *parent = GetPointer(Holder);
|
||||
const auto *target = std::addressof(parent->*member);
|
||||
return static_cast<const uint8_t *>(static_cast<const void *>(target)) - static_cast<const uint8_t *>(static_cast<const void *>(parent));
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
struct GetMemberPointerTraits;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user