std::remove_pointer
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.
Member types
| Name | Description |
|---|---|
type | the type pointed to by T or T if it's not a pointer |
Helper types
template< class T > using remove_pointer_t = typename remove_pointer<T>::type; | (since C++14) |
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; };
|
Example
#include <type_traits>
static_assert
(
std::is_same_v<int, int> &&
!std::is_same_v<int, int*> &&
!std::is_same_v<int, int**> &&
!std::is_same_v<int*, int**> &&
std::is_same_v<int, std::remove_pointer_t<int>> &&
std::is_same_v<int, std::remove_pointer_t<int*>> &&
!std::is_same_v<int, std::remove_pointer_t<int**>> &&
std::is_same_v<int*,std::remove_pointer_t<int**>> &&
std::is_same_v<int, std::remove_pointer_t<int* const>> &&
std::is_same_v<int, std::remove_pointer_t<int* volatile>> &&
std::is_same_v<int, std::remove_pointer_t<int* const volatile>>
);
int main() {}
See also
|
(C++11) | checks if a type is a pointer type (class template) |
|
(C++11) | adds a pointer to the given type (class template) |
|
(C++26) | removes a pointer from reflected type (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/types/remove_pointer