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