Namespaces
Variants

std:: reference_constructs_from_temporary

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
定義先ヘッダ <type_traits>
template < class T, class U >
struct reference_constructs_from_temporary ;
(C++23以降)

U がスカラ型または cv void である場合、 V std:: remove_cv_t < U > とし、それ以外の場合は U とする。 T が参照型であり、仮想的な式 e decltype ( e ) V となる場合、変数定義 T ref ( e ) ; が well-formed であり、 一時オブジェクトが ref にバインドされるならば、メンバ定数 value true に設定する。それ以外の場合、 value false となる。

T がconst修飾(volatile修飾ではない)オブジェクト型への左辺値参照型、または右辺値参照型である場合、 std:: remove_reference_t < T > std:: remove_reference_t < U > はともに 完全型 cv void または 境界不明な配列 でなければならない。そうでない場合、動作は未定義となる。

上記のテンプレートのインスタンス化が、直接的または間接的に不完全型に依存しており、その型が仮に完全化された場合に異なる結果をもたらす可能性がある場合、その動作は未定義です。

プログラムが std::reference_constructs_from_temporary または std::reference_constructs_from_temporary_v に対する特殊化を追加する場合、その動作は未定義です。

目次

ヘルパー変数テンプレート

template < class T, class U >

inline constexpr bool reference_constructs_from_temporary_v =

std :: reference_constructs_from_temporary < T, U > :: value ;
(C++23以降)

std::integral_constantから継承

メンバ定数

value
[static]
true T が参照型であり、直接初期化において U 値が T に束縛可能で、一時オブジェクトが参照に束縛される場合は false それ以外の場合
(公開静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換し、 value を返す
(公開メンバ関数)
operator()
(C++14)
value を返す
(公開メンバ関数)

メンバ型

定義
value_type bool
type std:: integral_constant < bool , value >

注記

std::reference_constructs_from_temporary は、常にダングリング参照を生成する一部のケースを拒否するために使用できます。

コンパイラが CWG1696 を実装している場合、メンバー初期化子リストを使用して一時オブジェクトの参照へのバインドを拒否することも可能です。

#include <type_traits>
static_assert(std::reference_constructs_from_temporary_v<int&&, int> == true);
static_assert(std::reference_constructs_from_temporary_v<const int&, int> == true);
static_assert(std::reference_constructs_from_temporary_v<int&&, int&&> == false);
static_assert(std::reference_constructs_from_temporary_v<const int&, int&&> == false);
static_assert(std::reference_constructs_from_temporary_v<int&&, long&&> == true);
static_assert(std::reference_constructs_from_temporary_v<int&&, long> == true);
int main() {}

関連項目

型が特定の引数に対するコンストラクタを持つかどうかをチェックする
(クラステンプレート)
新しい tuple を構築する
( std::tuple<Types...> の公開メンバ関数)
新しい pair を構築する
( std::pair<T1,T2> の公開メンバ関数)
引数のタプルからオブジェクトを構築する
(関数テンプレート)