std::remove_pointer
提供: cppreference.com
ヘッダ <type_traits> で定義
|
||
template< class T > struct remove_pointer; |
(C++11以上) | |
T
の指す先の型であるメンバ型 type
が提供されます。 または、 T
がポインタでなければ、 type
は T
と同じです。
目次 |
[編集] メンバ型
名前 | 定義 |
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;}; |
[編集] 例
Run this code
#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
[編集] 関連項目
(C++11) |
型がポインタ型かどうか調べます (クラステンプレート) |
(C++11) |
指定された型にポインタを追加します (クラステンプレート) |