名前空間
変種

std::remove_pointer

提供: cppreference.com
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
型サポート
型の性質
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(C++20未満)
(C++11)(C++20で非推奨)
(C++11)
型特性定数
メタ関数
(C++17)
定数評価文脈
サポートされている操作
関係と性質の問い合わせ
型変更
(C++11)(C++11)(C++11)
型変換
(C++11)
(C++11)
(C++17)
(C++11)(C++20未満)(C++17)
 
<tbody> </tbody>
ヘッダ <type_traits> で定義
template< class T > struct remove_pointer;
(C++11以上)

T の指す先の型であるメンバ型 type が提供されます。 または、 T がポインタでなければ、 typeT と同じです。

メンバ型

名前 定義
type T の指す先の型、または T がポインタでなければ T

ヘルパークラス

<tbody> </tbody>
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 <iostream>
#include <type_traits>

template<class T1, class T2>
void print_is_same() 
{
    std::cout << std::is_same<T1, T2>() << '\n';
}

void print_separator() 
{
    std::cout << "-----\n";
}

int main() 
{
    std::cout << std::boolalpha;

    print_is_same<int, int>();   // true
    print_is_same<int, int*>();  // false
    print_is_same<int, int**>(); // false

    print_separator();

    print_is_same<int, std::remove_pointer<int>::type>();   // true
    print_is_same<int, std::remove_pointer<int*>::type>();  // true
    print_is_same<int, std::remove_pointer<int**>::type>(); // false

    print_separator();

    print_is_same<int, std::remove_pointer<int* const>::type>();          // true
    print_is_same<int, std::remove_pointer<int* volatile>::type>();       // true
    print_is_same<int, std::remove_pointer<int* const volatile>::type>(); // true
}

出力:

true
false
false
-----
true
true
false
-----
true
true
true

関連項目

型がポインタ型かどうか調べます
(クラステンプレート) [edit]
指定された型にポインタを追加します
(クラステンプレート) [edit]