10
I'm trying to do some template metaprogramming and I'm finding the need to "extract" the highest index of a specialization of some structure in some type.
For example, if I have some types:
struct A
{
template<unsigned int> struct D;
template<> struct D<0> { };
};
struct B
{
template<unsigned int> struct D;
template<> struct D<0> { };
template<> struct D<1> { };
};
struct C
{
template<unsigned int> struct D;
template<> struct D<0> { };
template<> struct D<1> { };
template<> struct D<2> { };
};
How can I then write a metafunction like this:
template<class T>
struct highest_index
{
typedef ??? type;
// could also be: static size_t const index = ???;
};
to give me the highest-indexed D that has been specialized inside an arbitrary struct like the ones above, without requiring the struct to have declared the count explicitly?