Just write this:
const int n = sizeof...(T);
Note that n is a constant expression (known at compile time), which means you can use it where a constant expression is required, for example:
std::array<int, n> a;
Note that if you want to calculate the aggregated size of packed types (as opposed to the number of types in a package), then you should do something like this:
template<std::size_t ...> struct add_all : std::integral_constant< std::size_t,0 > {}; template<std::size_t X, std::size_t ... Xs> struct add_all<X,Xs...> : std::integral_constant< std::size_t, X + add_all<Xs...>::value > {};
then do the following:
constexpr auto size = add_all< sizeof(T)... >::value;
Hope this helps.
Nawaz Aug 19 '12 at 5:00 2012-08-19 05:00
source share