#include using namespace boost::mpl; template < typename Enum > struct enum_size { static unsigned const size=0 //specializations should return //the actual value for given Enum. ; }; template < typename... Pairs > struct enums_offsets_impl ; template < typename Derived > struct enums_offsets_impl < Derived > { static unsigned const offset=0; int* get() { return static_cast(*this).buffer(); } }; template < typename Derived , typename Tag , typename Enum , typename... Pairs > struct enums_offsets_impl < Derived , pair , Pairs... > : enums_offsets_impl < Derived , Pairs... > { typedef enums_offsets_impl < Derived , Pairs... > super_t; static unsigned const offset=enum_size::size+super_t::offset; using super_t:: get //bring overloaded get(Tag)'s from super types //in scope. ; int get(Tag) { return get()[super_t::offset]; } }; template < typename... Pairs > struct enums_offsets ; template < typename... Tags , typename... Enums > struct enums_offsets < pair... > : enums_offsets_impl < enums_offsets < pair... > , pair... > { typedef enums_offsets_impl < enums_offsets < pair... > , pair... > super_t; int my_buffer[super_t::offset]; enums_offsets() { for(unsigned i=0; istruct enum_size { static unsigned const size=2; }; template<>struct enum_size { static unsigned const size=3; }; template<>struct enum_size { static unsigned const size=4; }; typedef enums_offsets < pair , pair , pair > eos_t; #include int main() { std::cout<<":eos_t::offset="<