std::remove_pointer
來自 cppreference.com
定義於標頭檔案 <type_traits> |
||
template< class T > struct remove_pointer; |
(C++11 起) | |
提供成員 typedef type
,它是 T
指向的型別,如果 T
不是指標,則 type
與 T
相同。
如果程式為 std::remove_pointer
新增特殊化,則行為未定義。
目錄 |
[編輯] 成員型別
名稱 | 定義 |
型別
|
T 指向的型別,如果 T 不是指標,則為 T |
[編輯] 輔助型別
template< class T > using remove_pointer_t = typename remove_pointer<T>::type; |
(C++14 起) | |
[編輯] 可能的實現
template<class T> struct remove_pointer { typedef T type; }; template<class T> struct remove_pointer<T*> { typedef T type; }; template<class T> struct remove_pointer<T* const> { typedef T type; }; template<class T> struct remove_pointer<T* volatile> { typedef T type; }; template<class T> struct remove_pointer<T* const volatile> { typedef T type; }; |
[編輯] 示例
執行此程式碼
#include <type_traits> static_assert ( std::is_same_v<int, int> == true && std::is_same_v<int, int*> == false && std::is_same_v<int, int**> == false && std::is_same_v<int, std::remove_pointer_t<int>> == true && std::is_same_v<int, std::remove_pointer_t<int*>> == true && std::is_same_v<int, std::remove_pointer_t<int**>> == false && std::is_same_v<int, std::remove_pointer_t<int* const>> == true && std::is_same_v<int, std::remove_pointer_t<int* volatile>> == true && std::is_same_v<int, std::remove_pointer_t<int* const volatile>> == true ); int main() {}
[編輯] 另請參閱
(C++11) |
檢查型別是否為指標型別 (類模板) |
(C++11) |
向給定型別新增指標 (類模板) |