std::remove_pointer
Определён в заголовочном файле <type_traits> | ||
|---|---|---|
template< class T > struct remove_pointer; | (начиная с C++11) |
Предоставляет псевдоним типа-члена type, который является типом, на который указывает T, или, если T не является указателем, то type совпадает с T.
Если программа добавляет специализации для std::remove_pointer, поведение не определено.
Типы-члены
| Имя | Описание |
|---|---|
type | тип, на который указывает 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> &&
!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() {}
См. также
|
(C++11) | проверяет, является ли тип типом указателя (шаблон класса) |
|
(C++11) | добавляет указатель к заданному типу (шаблон класса) |
|
(C++26) | удаляет указатель из отражённого типа (функция) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/types/remove_pointer