<type_traits>

類模板
<type_traits>

std::remove_pointer

template <class T> struct remove_pointer;
移除指標
獲取被指向的型別T(如果T是 指標型別)。

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

如果已知T指標型別,即它所指向的型別。否則,它與T相同,保持不變。

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

模板引數

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_pointer
#include <iostream>
#include <type_traits>

int main() {
  typedef std::remove_pointer<int>::type A;          // int
  typedef std::remove_pointer<int*>::type B;         // int
  typedef std::remove_pointer<int**>::type C;        // int*
  typedef std::remove_pointer<const int*>::type D;   // const int
  typedef std::remove_pointer<int* const>::type E;   // 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: false
D: false
D: true


另見