Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/types/rank"

From cppreference.com
< cpp‎ | types
m (templated see-also list items.)
(formatting)
Line 20: Line 20:
 
{{eq fun cpp
 
{{eq fun cpp
 
  | 1=
 
  | 1=
template< class T>
+
template<class T>
 
struct rank : std::integral_constant<std::size_t, 0> {};
 
struct rank : std::integral_constant<std::size_t, 0> {};
template< class T>
+
 
 +
template<class T>
 
struct rank<T[]> : public std::integral_constant<std::size_t, rank<T>::value + 1> {};
 
struct rank<T[]> : public std::integral_constant<std::size_t, rank<T>::value + 1> {};
template< class T, size_t N >
+
 
 +
template<class T, size_t N >
 
struct rank<T[N]> : public std::integral_constant<std::size_t, rank<T>::value + 1> {};
 
struct rank<T[N]> : public std::integral_constant<std::size_t, rank<T>::value + 1> {};
 
}}
 
}}
Line 34: Line 36:
 
#include <iostream>
 
#include <iostream>
 
#include <type_traits>
 
#include <type_traits>
 +
 
template<typename A>
 
template<typename A>
 
void print_dim(const A&)
 
void print_dim(const A&)
Line 39: Line 42:
 
     std::cout << "The array has " << std::rank<A>::value << " dimensions\n";
 
     std::cout << "The array has " << std::rank<A>::value << " dimensions\n";
 
}
 
}
 +
 
int main()
 
int main()
 
{
 
{

Revision as of 16:32, 8 September 2011

Template:cpp/types/sidebar Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <type_traits>
</td>

<td></td> <td></td> </tr> <tr class="t-dcl ">

<td >
template< class T >
struct rank;
</td>

<td class="t-dcl-nopad"> </td> <td > Template:mark c++11 feature </td> </tr> Template:ddcl list end

If T is an array type, provides the member constant value equal to the number of dimensions of the array. For any other type, value is 0.

Contents

Member objects

Template:tdcl list begin Template:tdcl list hitem Template:tdcl list item Template:tdcl list end

Equivalent definition

Template:eq fun cpp

Example

Template:example cpp

See also

(C++11)
checks if a type is an array type
(class template) [edit]
(C++11)
obtains the size of an array type along a specified dimension
(class template) [edit]
removes one extent from the given array type
(class template) [edit]
removes all extents from the given array type
(class template) [edit]