< cpp‎ | types
Metaprogramming library
Type traits
Type categories
Type properties
(C++11)(until C++20*)
(C++11)(deprecated in C++20)
Type trait constants
Supported operations
Relationships and property queries
Type modifications

Type transformations
(C++11)(deprecated in C++23)
(C++11)(deprecated in C++23)

(C++11)(until C++20*)(C++17)
Compile-time rational arithmetic
Compile-time integer sequences
Defined in header <type_traits>
template< class T >
struct remove_pointer;
(since C++11)

Provides the member typedef type which is the type pointed to by T, or, if T is not a pointer, then type is the same as T.

If the program adds specializations for std::remove_pointer, the behavior is undefined.


[edit] Member types

Name Definition
type the type pointed to by T or T if it's not a pointer

[edit] Helper types

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

[edit] Possible implementation

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] Example

#include <type_traits>
    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] See also

checks if a type is a pointer type
(class template) [edit]
adds a pointer to the given type
(class template) [edit]