<type_traits>

類模板
<type_traits>

std::remove_all_extents

template <class T> struct remove_all_extents;
移除所有陣列維度
獲取最深層陣列元素的型別T(如果T是陣列型別)。

轉換後的類型別名為成員型別remove_all_extents::type.

如果已知T是陣列型別,則此型別與最深層陣列元素的型別相同。否則,成員型別與...相同T.

請注意,對於多維陣列,所有維度都會被移除(有關移除陣列型別的單個維度,請參閱 remove_extent)。

此類僅使用另一種型別作為模型來獲取型別,但不會在這些型別之間轉換值或物件。

模板引數

T
一個型別。

成員型別

成員型別定義
型別如果已知T是陣列,最深層陣列元素的型別是T.
否則,T

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// remove_all_extents
#include <iostream>
#include <type_traits>

int main() {
  typedef std::remove_all_extents<int>::type A;                // int
  typedef std::remove_all_extents<int[24]>::type B;            // int
  typedef std::remove_all_extents<int[24][60]>::type C;        // int
  typedef std::remove_all_extents<int[][60]>::type D;          // int
  typedef std::remove_all_extents<const int[10]>::type E;      // const int

  std::cout << std::boolalpha;
  std::cout << "typedefs of int:" << std::endl;
  std::cout << "A: " << std::is_same<int,A>::value << std::endl;
  std::cout << "B: " << std::is_same<int,B>::value << std::endl;
  std::cout << "C: " << std::is_same<int,C>::value << std::endl;
  std::cout << "D: " << std::is_same<int,D>::value << std::endl;
  std::cout << "E: " << std::is_same<int,E>::value << std::endl;

  return 0;
}

輸出
typedefs of int:
A: true
B: true
C: true
D: true
E: false


另見