allow/raw/linear: add typed offset query

This commit is contained in:
Danny Robson 2018-05-18 16:51:42 +10:00
parent b7a4b8d1c0
commit 7d315c8095

View File

@ -82,6 +82,16 @@ namespace util::alloc::raw {
size_t offset (const void*) const;
template <typename ValueT>
size_t
offset (ValueT const *ptr) const
{
CHECK_MOD (reinterpret_cast<uintptr_t> (ptr), sizeof (ValueT));
CHECK_MOD (reinterpret_cast<uintptr_t> (data ()), sizeof (ValueT));
return ptr - util::cast::alignment<ValueT const*> (data ());
}
template <typename T>
size_t
offset (util::view<T*> ptr) const