Skip to content

Instantly share code, notes, and snippets.

@catchouli
Created January 4, 2015 14:57
Show Gist options
  • Save catchouli/2cb39715209df0da7866 to your computer and use it in GitHub Desktop.
Save catchouli/2cb39715209df0da7866 to your computer and use it in GitHub Desktop.
a relic from the deepest darkest corners of c++
template <typename T, typename F>
size_t offset(F T::* ptr)
{
T* typePtr = (T*)nullptr;
F* memberPtr = &(typePtr->*ptr);
uintptr_t offset = (uintptr_t)memberPtr - (uintptr_t)typePtr;
return offset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment