名稱空間
變體
操作

std::remove_cvref

來自 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)
型別轉換
(C++11)(C++23 中已棄用)
(C++11)(C++23 中已棄用)
(C++11)
remove_cvref
(C++20)
(C++11)(直到 C++20*)(C++17)

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

如果型別 T 是引用型別,則提供成員 typedef type,其為 T 所引用的型別,並去除了其最頂層的 cv 限定符。否則 typeT,並去除了其最頂層的 cv 限定符。

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

目錄

[編輯] 成員型別

名稱 定義
型別 如果 T 不是引用,則為 T 引用的型別或 T 本身,並移除了頂層 cv 限定符

[編輯] 輔助型別

template< class T >
using remove_cvref_t = remove_cvref<T>::type;
(C++20 起)

[編輯] 可能實現

template<class T>
struct remove_cvref
{
    using type = std::remove_cv_t<std::remove_reference_t<T>>;
};

[編輯] 注意

特性測試 標準 特性
__cpp_lib_remove_cvref 201711L (C++20) std::remove_cvref

[編輯] 示例

#include <type_traits>
 
int main()
{
    static_assert(std::is_same_v<std::remove_cvref_t<int>, int>);
    static_assert(std::is_same_v<std::remove_cvref_t<int&>, int>);
    static_assert(std::is_same_v<std::remove_cvref_t<int&&>, int>);
    static_assert(std::is_same_v<std::remove_cvref_t<const int&>, int>);
    static_assert(std::is_same_v<std::remove_cvref_t<const int[2]>, int[2]>);
    static_assert(std::is_same_v<std::remove_cvref_t<const int(&)[2]>, int[2]>);
    static_assert(std::is_same_v<std::remove_cvref_t<int(int)>, int(int)>);
}

[編輯] 參閱

從給定型別中移除 const 和/或 volatile 限定符
(類模板) [編輯]
從給定型別中移除引用
(類模板) [編輯]
(C++11)
當函式引數按值傳遞時應用型別轉換
(類模板) [編輯]