std::reference_converts_from_temporary
來自 cppreference.com
定義於標頭檔案 <type_traits> |
||
template< class T, class U > struct reference_converts_from_temporary; |
(C++23 起) | |
設 V
為 std::remove_cv_t<U>(如果 U
是標量型別或 cv void),否則為 U
。如果 T
是引用型別,並且給定一個假設表示式 e,使得 decltype(e) 是 V
,變數定義 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
成員常量
值 [靜態] |
true 如果 T 是引用型別,U 值可以在複製初始化中繫結到 T ,並且臨時物件將繫結到引用,否則為 false(public static 成員常量) |
成員函式
operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
operator() (C++14) |
返回 value (公開成員函式) |
成員型別
型別 | 定義 |
value_type
|
bool |
型別
|
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) |
將一個或多個引數繫結到函式物件 (函式模板) |
(C++17) |
用一個或多個 variant 所持有的引數呼叫所提供的函式物件(函式模板) |
構造一個新的 std::function 例項( std::function<R(Args...)> 的公開成員函式) | |
構造新的 std::move_only_function 物件( std::move_only_function 的公開成員函式) | |
構造任務物件 ( std::packaged_task<R(Args...)> 的公開成員函式) |