util/Cast: add "const" overload

This commit is contained in:
Max Kellermann 2014-07-14 16:44:17 +02:00
parent 72eedb1c98
commit d8558a3af3
1 changed files with 13 additions and 0 deletions

View File

@ -93,4 +93,17 @@ ContainerCast(A &a, A C::*member)
return *OffsetCast<C, A>(&a, ContainerAttributeOffset<C, A>(member));
}
/**
* Cast the given pointer to a struct member to its parent structure.
*/
template<class C, class A>
#if defined(__clang__) || GCC_CHECK_VERSION(4,7)
constexpr
#endif
static inline const C &
ContainerCast(const A &a, A C::*member)
{
return *OffsetCast<const C, const A>(&a, ContainerAttributeOffset<C, A>(member));
}
#endif