std::remove_pointer - cppreference.com
来自cppreference.com
template< class T > struct remove_pointer; |
(C++11 起) | |
提供成员 typedef type,它是 T 所指向的类型,或若 T 不是指针,则 type 与 T 相同。
如果程序添加了 std::remove_pointer 的特化,那么行为未定义。
成员类型
| 名称 | 定义 |
type
|
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() {}