std::remove_cvref
來自 cppreference.com
定義於標頭檔案 <type_traits> |
||
template< class T > struct remove_cvref; |
(C++20 起) | |
如果型別 T
是引用型別,則提供成員 typedef type
,其為 T
所引用的型別,並去除了其最頂層的 cv 限定符。否則 type
為 T
,並去除了其最頂層的 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)>); }
[編輯] 參閱
(C++11)(C++11)(C++11) |
從給定型別中移除 const 和/或 volatile 限定符 (類模板) |
(C++11) |
從給定型別中移除引用 (類模板) |
(C++11) |
當函式引數按值傳遞時應用型別轉換 (類模板) |