Two years later, but an alternative solution that can be computed by the compiler (if you are not against different syntax):
template < typename ... Types > struct SizeOf; template < typename TFirst > struct SizeOf < TFirst > { static const auto Value = (sizeof(TFirst)); }; template < typename TFirst, typename ... TRemaining > struct SizeOf < TFirst, TRemaining ... > { static const auto Value = (sizeof(TFirst) + SizeOf<TRemaining...>::Value); };
Used as const int size = SizeOf<int, char, double>::Value; // 4 + 1 + 8 = 13 const int size = SizeOf<int, char, double>::Value; // 4 + 1 + 8 = 13
source share