Created
November 15, 2016 19:35
-
-
Save hutorny/69a568de22aa59e2c64957fd0cacd52e to your computer and use it in GitHub Desktop.
This file contains 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
/* 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