std::reference_converts_from_temporary
From cppreference.com
| ヘッダ <type_traits> で定義 |
||
| template< class T, class U > struct reference_converts_from_temporary; |
(C++23から) | |
Vを、Uがスカラ型またはcv voidの場合はstd::remove_cv_t<U>とし、それ以外の場合はUとする。Tが参照型であり、decltype(e)がVであるような仮想的な式eが与えられたとき、変数定義T ref = e;が整形式であり、一時オブジェクトをrefに束縛する場合、valueがtrueに等しいメンバ定数を提供する。それ以外の場合、valueはfalseである。
Tが、const修飾されているがvolatile修飾されていないオブジェクト型への左辺値参照型、または右辺値参照型である場合、std::remove_reference_t<T>とstd::remove_reference_t<U>は両方とも完全型、cv void、または境界未知の配列でなければならない。そうでなければ、動作は未定義である。
上記のテンプレートのインスタンス化が、直接的または間接的に不完全な型に依存し、その型が仮に完全になった場合にそのインスタンス化が異なる結果を生み出す可能性がある場合、動作は未定義です。
プログラムがstd::reference_converts_from_temporaryまたはstd::reference_converts_from_temporary_vの特殊化を追加した場合、動作は未定義である。
目次 |
[編集] ヘルパー変数テンプレート
| template< class T, class U > inline constexpr bool reference_converts_from_temporary_v = |
(C++23から) | |
std::integral_constant から継承
メンバ定数
| value [static] |
Tが参照型であり、コピー初期化においてU値がTに束縛でき、一時オブジェクトが参照に束縛される場合はtrue、それ以外の場合はfalse(公開静的メンバ定数) |
メンバ関数
| operator bool |
オブジェクトを bool に変換し、value を返します。 (public member function) |
| operator() (C++14) |
value を返します。 (public member function) |
メンバ型
| 型 | 定義 |
value_type
|
bool |
type
|
std::integral_constant<bool, value> |
[編集] 備考
std::reference_converts_from_temporaryは、常にダングリング参照を生成するようなケースを拒否するために使用できる。
[編集] 例
このコードを実行
#include <type_traits> int main() {} static_assert( std::reference_converts_from_temporary_v<int&&, int> == true && std::reference_converts_from_temporary_v<const int&, int> == true && std::reference_converts_from_temporary_v<int&&, int&&> == false && std::reference_converts_from_temporary_v<const int&, int&&> == false && std::reference_converts_from_temporary_v<int&&, long&&> == true && std::reference_converts_from_temporary_v<int&&, long> == true);
[編集] 関連項目
| (C++11)(C++20) |
ある型が他の型に変換可能であるかをチェックする (クラステンプレート) |
| (C++17)(C++23) |
任意の呼び出し可能 (Callable)オブジェクトを所与の引数で呼び出す (戻り値の型を指定することも可能)(C++23以降) (関数テンプレート) |
| (C++11) |
1つ以上の引数を関数オブジェクトに束縛する (関数テンプレート) |
| (C++17) |
1つまたは複数の variant が保持する引数で、与えられたファンクタを呼び出す(function template) |
新しいstd::functionインスタンスを構築する( std::function<R(Args...)>のpublicメンバ関数) | |
新しい std::move_only_function オブジェクトを構築する( std::move_only_functionのpublicメンバ関数) | |
| タスクオブジェクトを構築する ( std::packaged_task<R(Args...)>のpublicメンバ関数) |