命名空间
变体
操作

std::remove_pointer

来自 cppreference.cn
< cpp‎ | types
 
 
元编程库
类型特性
类型类别
(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)
remove_pointer
(C++11)

类型转换
(C++11)(在 C++23 中弃用)
(C++11)(在 C++23 中弃用)
(C++11)
(C++11)(直到 C++20*)(C++17)

(C++11)
(C++17)
编译时有理算术
编译时整数序列
 
在头文件 <type_traits> 中定义
template< class T >
struct remove_pointer;
(自 C++11 起)

提供成员 typedef type,它是 T 指向的类型,或者,如果 T 不是指针,则 typeT 相同。

如果程序为 std::remove_pointer 添加特化,则行为未定义。

目录

[edit] 成员类型

名称 定义
type T 指向的类型,如果 T 不是指针,则为 T

[edit] 辅助类型

template< class T >
using remove_pointer_t = typename remove_pointer<T>::type;
(自 C++14 起)

[edit] 可能的实现

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; };

[edit] 示例

#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() {}

[edit] 参见

检查类型是否为指针类型
(类模板) [edit]
向给定类型添加指针
(类模板) [edit]