From f8da8b02615bc5b8a358407da147c97debc40e06 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 14 Jul 2014 16:02:02 +0200 Subject: util/Cast: add const overloads --- src/util/Cast.hxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util/Cast.hxx b/src/util/Cast.hxx index ca4b62832..8eb3479b8 100644 --- a/src/util/Cast.hxx +++ b/src/util/Cast.hxx @@ -41,6 +41,15 @@ OffsetPointer(void *p, ptrdiff_t offset) return (char *)p + offset; } +/** + * Offset the given pointer by the specified number of bytes. + */ +static inline constexpr const void * +OffsetPointer(const void *p, ptrdiff_t offset) +{ + return (const char *)p + offset; +} + template static inline constexpr T * OffsetCast(U *p, ptrdiff_t offset) @@ -48,6 +57,13 @@ OffsetCast(U *p, ptrdiff_t offset) return reinterpret_cast(OffsetPointer(p, offset)); } +template +static inline constexpr T * +OffsetCast(const U *p, ptrdiff_t offset) +{ + return reinterpret_cast(OffsetPointer(p, offset)); +} + /** * Cast the given pointer to a struct member to its parent structure. */ -- cgit v1.2.3