std:: remove_pointer
From cppreference.net
C++
Metaprogramming library
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<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)
|
型がポインタ型かどうかをチェックする
(クラステンプレート) |
|
(C++11)
|
指定された型にポインタを追加する
(クラステンプレート) |