std::remove_reference
From cppreference.com
| ヘッダ <type_traits> で定義 |
||
| template< class T > struct remove_reference; |
(C++11以降) | |
型Tが参照型である場合、メンバー型typeはTが参照している型となります。それ以外の場合、typeはTとなります。
プログラムがstd::remove_referenceの特殊化を追加した場合、動作は未定義です。
目次 |
[編集] メンバー型
| 名前 | 定義 |
type
|
Tが参照している型、または参照でない場合はT |
[編集] ヘルパー型
| template< class T > using remove_reference_t = typename remove_reference<T>::type; |
(C++14以降) | |
[編集] 実装例
template<class T> struct remove_reference { typedef T type; }; template<class T> struct remove_reference<T&> { typedef T type; }; template<class T> struct remove_reference<T&&> { typedef T type; }; |
[編集] 例
このコードを実行
#include <iostream> #include <type_traits> int main() { std::cout << std::boolalpha; std::cout << "std::remove_reference<int>::type is int? " << std::is_same<int, std::remove_reference<int>::type>::value << '\n'; std::cout << "std::remove_reference<int&>::type is int? " << std::is_same<int, std::remove_reference<int&>::type>::value << '\n'; std::cout << "std::remove_reference<int&&>::type is int? " << std::is_same<int, std::remove_reference<int&&>::type>::value << '\n'; std::cout << "std::remove_reference<const int&>::type is const int? " << std::is_same<const int, std::remove_reference<const int&>::type>::value << '\n'; }
出力
std::remove_reference<int>::type is int? true std::remove_reference<int&>::type is int? true std::remove_reference<int&&>::type is int? true std::remove_reference<const int&>::type is const int? true
[編集] 関連項目
| (C++11) |
型が左辺値参照または右辺値参照であるかをチェックする (クラステンプレート) |
| (C++11)(C++11) |
与えられた型に左辺値または右辺値参照を追加する (クラステンプレート) |
| (C++20) |
std::remove_cv と std::remove_reference を組み合わせたもの (クラステンプレート) |