util/Cast: add const overloads
This commit is contained in:
parent
393cb7fd7d
commit
f8da8b0261
@ -41,6 +41,15 @@ OffsetPointer(void *p, ptrdiff_t offset)
|
|||||||
return (char *)p + 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>
|
template<typename T, typename U>
|
||||||
static inline constexpr T *
|
static inline constexpr T *
|
||||||
OffsetCast(U *p, ptrdiff_t offset)
|
OffsetCast(U *p, ptrdiff_t offset)
|
||||||
@ -48,6 +57,13 @@ OffsetCast(U *p, ptrdiff_t offset)
|
|||||||
return reinterpret_cast<T *>(OffsetPointer(p, 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.
|
* Cast the given pointer to a struct member to its parent structure.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user