命名空间
变体
操作

std::remove_pointer

来自 cppreference.cn
< cpp‎ | 类型
 
 
元编程库
类型特性
类型类别
(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 添加特殊化,则行为未定义。

目录

[编辑] 成员类型

名称 定义
类型 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() {}

[编辑] 另请参阅

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