<type_traits>

類模板
<type_traits>

std::remove_reference

template <class T> struct remove_reference;
移除引用
獲取T所引用的非引用型別T所引用的。

轉換後的類型別名為成員型別remove_reference::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_reference
#include <iostream>
#include <type_traits>

int main() {
  typedef int&& rval_int;
  typedef std::remove_reference<int>::type A;
  typedef std::remove_reference<int&>::type B;
  typedef std::remove_reference<int&&>::type C;
  typedef std::remove_reference<rval_int>::type D;

  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;

  return 0;
}

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


另見