std::is_reference
提供: cppreference.com
ヘッダ <type_traits> で定義
|
||
template< class T > struct is_reference; |
(C++11以上) | |
T
が参照型 (左辺値参照または右辺値参照) であれば、 true に等しいメンバ定数 value
が提供されます。 それ以外の型に対しては、 value
は false です。
is_reference
または is_reference_v
(C++17以上) に対して特殊化を追加するプログラムは未定義です。
目次 |
[編集] テンプレート引数
T | - | 調べる型 |
[編集] ヘルパー変数テンプレート
template< class T > inline constexpr bool is_reference_v = is_reference<T>::value; |
(C++17以上) | |
std::integral_constant から継承
メンバ定数
value [静的] |
T が参照型ならば true、そうでなければ false (パブリック静的メンバ定数) |
メンバ関数
operator bool |
オブジェクトを bool に変換します。 value を返します (パブリックメンバ関数) |
operator() (C++14) |
value を返します (パブリックメンバ関数) |
メンバ型
型 | 定義 |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
[編集] 実装例
template <class T> struct is_reference : std::false_type {}; template <class T> struct is_reference<T&> : std::true_type {}; template <class T> struct is_reference<T&&> : std::true_type {}; |
[編集] 例
Run this code
#include <iostream> #include <type_traits> class A {}; int main() { std::cout << std::boolalpha; std::cout << std::is_reference<A>::value << '\n'; std::cout << std::is_reference<A&>::value << '\n'; std::cout << std::is_reference<A&&>::value << '\n'; std::cout << std::is_reference<int>::value << '\n'; std::cout << std::is_reference<int&>::value << '\n'; std::cout << std::is_reference<int&&>::value << '\n'; }
出力:
false true true false true true
[編集] 関連項目
(C++11) |
型が左辺値参照かどうか調べます (クラステンプレート) |
(C++11) |
型が右辺値参照かどうか調べます (クラステンプレート) |