std::remove_cvref
出自cppreference.com
| 在標頭 <type_traits> 定義
|
||
| |
(C++20 起) | |
若類型 T 為引用類型,則提供成員 type,它是移除了最頂層 cv 限定符的 T 所引用的類型��否則 type 為移除最頂層 cv 限定符的 T。
如果程序添加了 std::remove_cvref 的特化,那麼行為未定義。
成員類型
| 名稱 | 定義 |
type
|
T 所引用的類型,或若 T 不是引用則為其自身,移除頂層 cv 限定符
|
輔助類型
| |
(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) |
應用當按值傳遞實參給函數時所進行的類型變換 (類模板) |