diff --git a/src/util/Cast.hxx b/src/util/Cast.hxx index c49d18eaa..887137da4 100644 --- a/src/util/Cast.hxx +++ b/src/util/Cast.hxx @@ -93,4 +93,17 @@ ContainerCast(A &a, A C::*member) return *OffsetCast(&a, ContainerAttributeOffset(member)); } +/** + * Cast the given pointer to a struct member to its parent structure. + */ +template +#if defined(__clang__) || GCC_CHECK_VERSION(4,7) +constexpr +#endif +static inline const C & +ContainerCast(const A &a, A C::*member) +{ + return *OffsetCast(&a, ContainerAttributeOffset(member)); +} + #endif