diff options
author | Max Kellermann <max@duempel.org> | 2014-07-14 16:02:02 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-07-14 16:02:02 +0200 |
commit | f8da8b02615bc5b8a358407da147c97debc40e06 (patch) | |
tree | 7abc6a67e5efa995ddce5cfcb8c644f27d1e226a | |
parent | 393cb7fd7de87c535e4c90af0a024d75842582f9 (diff) |
util/Cast: add const overloads
-rw-r--r-- | src/util/Cast.hxx | 16 |
1 files changed, 16 insertions, 0 deletions
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<typename T, typename U> static inline constexpr T * OffsetCast(U *p, ptrdiff_t offset) @@ -48,6 +57,13 @@ OffsetCast(U *p, ptrdiff_t offset) return reinterpret_cast<T *>(OffsetPointer(p, offset)); } +template<typename T, typename U> +static inline constexpr T * +OffsetCast(const U *p, ptrdiff_t offset) +{ + return reinterpret_cast<const T *>(OffsetPointer(p, offset)); +} + /** * Cast the given pointer to a struct member to its parent structure. */ |