I have a function that takes a multidimensional std::vector and requires the depth (or the number of dimensions) to be passed in as a template parameter. Instead of
Assuming that a container is any type that has value_type and iterator member types (standard library containers satisfy this requirement) or a C-style array, we can easily generalize Cruz Jean's solution:
template
struct rank : std::integral_constant {};
// C-style arrays
template
struct rank
: std::integral_constant::value> {};
template
struct rank
: std::integral_constant::value> {};
// Standard containers
template
struct rank>
: std::integral_constant::value> {};
int main() {
using T1 = std::list, 4>>>;
using T2 = std::list[4]>>;
std::cout << rank(); // Output : 4
std::cout << rank(); // Output : 4
}
Container types can be further restricted if needed.