From d8558a3af333ee02603a4a07c5bc7031d624f72b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Jul 2014 16:44:17 +0200 Subject: util/Cast: add "const" overload --- src/util/Cast.hxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') 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 -- cgit v1.2.3