Namespaces
Variants

std:: remove_pointer

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
ヘッダーで定義 <type_traits>
template < class T >
struct remove_pointer ;
(C++11以降)

T が指す型であるメンバ型 type を提供します。または、 T がポインタでない場合、 type T と同じ型になります。

プログラムが std::remove_pointer に対する特殊化を追加する場合、動作は未定義です。

目次

メンバー型

名前 定義
type 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() {}

関連項目

(C++11)
型がポインタ型かどうかをチェックする
(クラステンプレート)
指定された型にポインタを追加する
(クラステンプレート)