util/Cast: reverse operands in ContainerAttributeOffset()
The result shall be positive.
This commit is contained in:
parent
edd9d16c84
commit
9d63c8220b
@ -53,7 +53,7 @@ template<class C, class A>
|
||||
static constexpr inline ptrdiff_t
|
||||
ContainerAttributeOffset(const C *null_c, const A C::*p)
|
||||
{
|
||||
return ptrdiff_t((const char *)null_c - (const char *)&(null_c->*p));
|
||||
return ptrdiff_t((const char *)&(null_c->*p) - (const char *)null_c);
|
||||
}
|
||||
|
||||
template<class C, class A>
|
||||
@ -70,7 +70,7 @@ template<class C, class A>
|
||||
static inline constexpr C &
|
||||
ContainerCast(A &a, const A C::*member)
|
||||
{
|
||||
return *OffsetCast<C, A>(&a, ContainerAttributeOffset<C, A>(member));
|
||||
return *OffsetCast<C, A>(&a, -ContainerAttributeOffset<C, A>(member));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +80,7 @@ template<class C, class A>
|
||||
static inline constexpr const C &
|
||||
ContainerCast(const A &a, const A C::*member)
|
||||
{
|
||||
return *OffsetCast<const C, const A>(&a, ContainerAttributeOffset<C, A>(member));
|
||||
return *OffsetCast<const C, const A>(&a, -ContainerAttributeOffset<C, A>(member));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user