std:: remove_reference
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_reference ; |
(C++11以降) | |
型
T
が参照型の場合、メンバ typedef
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)
|
型が
lvalue reference
または
rvalue reference
のいずれかであるかどうかをチェックする
(クラステンプレート) |
|
(C++11)
(C++11)
|
指定された型に
lvalue
または
rvalue
参照を追加する
(クラステンプレート) |
|
(C++20)
|
std::remove_cv
と
std::remove_reference
を組み合わせる
(クラステンプレート) |