[base] Move container_of to own file

This commit is contained in:
Joe Thornber 2016-02-24 14:42:37 +00:00
parent a5a53648c9
commit 6637a30618
1 changed files with 24 additions and 0 deletions

24
base/container_of.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef BASE_CONTAINER_OF_H
#define BASE_CONTAINER_OF_H
#include <stdlib.h>
//----------------------------------------------------------------
namespace base {
template<class P, class M>
size_t offsetof__(const M P::*member)
{
return (size_t) &( reinterpret_cast<P*>(0)->*member);
}
template<class P, class M>
P *container_of(M *ptr, M const P::*member)
{
return (P *)((char *)(ptr) - offsetof__(member));
}
}
//----------------------------------------------------------------
#endif