名稱空間
變體
操作

std::remove_reference

來自 cppreference.com
< cpp‎ | 型別
 
 
超程式設計庫
型別特性
型別類別
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
型別屬性
(C++11)
(C++11)
(C++14)
(C++11)(C++26 中已棄用)
(C++11)(直到 C++20*)
(C++11)(C++20 中已棄用)
(C++11)
型別特性常量
元函式
(C++17)
支援的操作
關係與屬性查詢
型別修改
(C++11)(C++11)(C++11)
remove_reference
(C++11)

型別轉換
(C++11)(C++23 中已棄用)
(C++11)(C++23 中已棄用)
(C++11)
(C++11)(直到 C++20*)(C++17)

(C++11)
(C++17)
編譯時有理數算術
編譯時整數序列
 
定義於標頭檔案 <type_traits>
template< class T >
struct remove_reference;
(C++11 起)

如果型別 T 是引用型別,則提供成員 typedef type,它是 T 所引用的型別。否則 typeT

如果程式為 std::remove_reference 新增特化,則行為是未定義的。

目錄

[編輯] 成員型別

名稱 定義
型別 T 所引用的型別,如果 T 不是引用,則為 T

[編輯] 輔助型別

template< class T >
using remove_reference_t = typename remove_reference<T>::type;
(C++14 起)

[編輯] 可能的實現

template<class T> struct remove_reference { typedef T type; };
template<class T> struct remove_reference<T&> { typedef T type; };
template<class T> struct remove_reference<T&&> { typedef T type; };

[編輯] 示例

#include <iostream>
#include <type_traits>
 
int main()
{
    std::cout << std::boolalpha;
 
    std::cout << "std::remove_reference<int>::type is int? "
              << std::is_same<int, std::remove_reference<int>::type>::value << '\n';
    std::cout << "std::remove_reference<int&>::type is int? "
              << std::is_same<int, std::remove_reference<int&>::type>::value << '\n';
    std::cout << "std::remove_reference<int&&>::type is int? "
              << std::is_same<int, std::remove_reference<int&&>::type>::value << '\n';
    std::cout << "std::remove_reference<const int&>::type is const int? "
              << std::is_same<const int,
                              std::remove_reference<const int&>::type>::value << '\n';
}

輸出

std::remove_reference<int>::type is int? true
std::remove_reference<int&>::type is int? true
std::remove_reference<int&&>::type is int? true
std::remove_reference<const int&>::type is const int? true

[編輯] 另請參閱

檢查型別是否為*左值引用*或*右值引用*
(類模板) [編輯]
向給定型別新增左值或右值引用
(類模板) [編輯]
結合了 std::remove_cvstd::remove_reference
(類模板) [編輯]