<type_traits>

類模板
<type_traits>

std::add_rvalue_reference

template <class T> struct add_rvalue_reference;
新增右值引用
獲取引用自T.

轉換後的類型別名為成員型別右值引用型別如下

  • 如果已知T如果是物件函式型別,則為T&&.
  • 否則(即T的 C++ 等效檔案是void或者左值引用或已經是右值引用),則保持T不變。

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

模板引數

T
一個型別。

成員型別

成員型別定義
型別如果已知T物件函式型別T&&
否則T

示例

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

int main() {
  typedef std::add_rvalue_reference<int>::type A;    // int&&
  typedef std::add_rvalue_reference<int&>::type B;   // int&  (no change)
  typedef std::add_rvalue_reference<int&&>::type C;  // int&& (no change)
  typedef std::add_rvalue_reference<int*>::type D;   // 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;

  return 0;
}

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


另見