Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* container_of, inspired by AndrewTsao */
template <class T, typename M>
constexpr T* container_of(M *m, const M T::*p) noexcept {
return reinterpret_cast<T*>(reinterpret_cast<char*>(m)
- reinterpret_cast<const ptrdiff_t>(
&(static_cast<const T *>(nullptr)->*p)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.