Last active
January 3, 2024 09:00
-
-
Save kerrytazi/8889c517367ea6ccd98d29f9265faa42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <cstddef> | |
template <typename TRet, typename TVal> | |
TRet *poff(TVal *ptr, ptrdiff_t offset) | |
{ | |
return reinterpret_cast<TRet *>(reinterpret_cast<char *>(ptr) + offset); | |
} | |
template <typename TRet, typename TVal> | |
TRet const *poff(TVal const *ptr, ptrdiff_t offset) | |
{ | |
return reinterpret_cast<TRet const *>(reinterpret_cast<const char *>(ptr) + offset); | |
} | |
template <typename TVal> | |
TVal *poff(TVal *ptr, ptrdiff_t offset) | |
{ | |
return poff<TVal, TVal>(ptr, offset); | |
} | |
template <typename TVal> | |
TVal const *poff(TVal const *ptr, ptrdiff_t offset) | |
{ | |
return poff<TVal, TVal>(ptr, offset); | |
} | |
template <typename TRet, typename TVal> | |
TRet voff(TVal *ptr, ptrdiff_t offset) | |
{ | |
return *poff<TRet>(ptr, offset); | |
} | |
template <typename TRet, typename TVal> | |
TRet voff(TVal const *ptr, ptrdiff_t offset) | |
{ | |
return *poff<TRet>(ptr, offset); | |
} | |
template <typename TVal> | |
void *roff(TVal *ptr, ptrdiff_t offset) | |
{ | |
return voff<void *>(ptr, offset); | |
} | |
template <typename TVal> | |
void const *roff(TVal const *ptr, ptrdiff_t offset) | |
{ | |
return voff<void const *>(ptr, offset); | |
} | |
template <typename TRet, typename TVal> | |
TRet *roff(TVal *ptr, ptrdiff_t offset) | |
{ | |
return voff<TRet *>(ptr, offset); | |
} | |
template <typename TRet, typename TVal> | |
TRet const *roff(TVal const *ptr, ptrdiff_t offset) | |
{ | |
return voff<TRet const *>(ptr, offset); | |
} | |
float *pmain(void *p, int off[]) | |
{ | |
return poff<float>(poff(p, off[0]), off[1]); | |
} | |
const float *pmainc(const void *p, int off[]) | |
{ | |
return poff<float>(poff(p, off[0]), off[1]); | |
} | |
float *rmain(void *p, int off[]) | |
{ | |
return roff<float>(roff(p, off[0]), off[1]); | |
} | |
const float *rmainc(const void *p, int off[]) | |
{ | |
return roff<float>(roff(p, off[0]), off[1]); | |
} | |
float vmain(void *p, int off[]) | |
{ | |
return voff<float>(roff(p, off[0]), off[1]); | |
} | |
float vmainc(const void *p, int off[]) | |
{ | |
return voff<float>(roff(p, off[0]), off[1]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment