std::remove_pointer
From cppreference.com
| ヘッダ <type_traits> で定義 |
||
| template< class T > struct remove_pointer; |
(C++11以降) | |
T が指す型、あるいは T がポインタでない場合は T と同じ型であるメンバエイリアス type を提供します。
プログラムが 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> == 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) |
型がポインタ型であるかをチェックする (クラステンプレート) |
| (C++11) |
与えられた型にポインタを追加する (クラステンプレート) |