std::indirectly_readable_traits
定義於標頭檔案 <iterator> |
||
template< class I > struct indirectly_readable_traits {}; |
(1) | (C++20 起) |
template< class T > struct indirectly_readable_traits<T*> : |
(2) | (C++20 起) |
template< class I > requires std::is_array_v<I> |
(3) | (C++20 起) |
template< class T > struct indirectly_readable_traits<const T> : |
(4) | (C++20 起) |
template< /* has-member-value-type */ T > struct indirectly_readable_traits<T> : |
(5) | (C++20 起) |
template< /* has-member-element-type */ T > struct indirectly_readable_traits<T> : |
(6) | (C++20 起) |
template< /* has-member-value-type */ T > requires /* has-member-element-type */<T> |
(7) | (C++20 起) |
template< /* has-member-value-type */ T > requires /* has-member-element-type */<T> && |
(8) | (C++20 起) |
輔助類和概念 |
||
template< class > struct /* cond-value-type */ {}; |
(1) | (僅作說明*) |
template< class T > requires std::is_object_v<T> |
(2) | (僅作說明*) |
template< class T > concept /* has-member-value-type */ = |
(3) | (僅作說明*) |
template< class T > concept /* has-member-element-type */ = |
(4) | (僅作說明*) |
計算模板引數的關聯值型別。如果關聯值型別存在,則由巢狀型別 `value_type` 表示,否則不定義 `value_type`。程式可以為程式定義型別特化 `indirectly_readable_traits`。
目錄 |
[編輯] 解釋
上述特化可以非正式地描述如下。
給定型別 `T`,其關聯值型別 `V` 的確定如下:
- 如果 `T` 是 const-qualified,`V` 是 const-unqualified `T` 的關聯值型別。
- 否則,如果 `T` 是陣列型別,`V` 是 cv-unqualified 陣列元素型別。
- 否則,首先確定條件值型別 `C`:
- 如果 `T` 是指標型別,`C` 是所指向的型別。
- 否則,如果 `T` 具有巢狀型別 `value_type` 和 `element_type`:
- 如果這些型別相同(不考慮 cv-qualification),`C` 是 `typename T::value_type`。
- 否則,`C` 未定義。
- 否則,如果 `T` 具有巢狀型別 `value_type` 但沒有 `element_type`,`C` 是 `typename T::value_type`。
- 否則,如果 `T` 具有巢狀型別 `element_type` 但沒有 `value_type`,`C` 是 `typename T::element_type`。
- 否則,`C` 未定義。
- 然後 `V` 根據 `C` 確定如下:
- 如果 `C` 未定義,或者 `C` 不是物件型別,則 `V` 未定義。
- 否則,`V` 是 cv-unqualified `C`。
[編輯] 注意
`value_type` 旨在與 `indirectly_readable` 型別(如迭代器)一起使用。它不打算與範圍一起使用。
[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 3446 | C++20 | 特化 (5,6) 對於同時具有 `value_type` 和 `element_type` 巢狀型別的型別是模糊的 |
添加了特化 (8) |
LWG 3541 | C++20 | LWG 3446 引入了歧義情況的硬錯誤 `value_type` 和 `element_type` 不同 |
添加了特化 (7) |
[編輯] 另請參閱
(C++20) |
透過應用運算子* 指定型別是間接可讀的(概念) |
(C++20)(C++20)(C++23)(C++20)(C++20)(C++20) |
計算迭代器的關聯型別 (別名模板) |
提供迭代器屬性的統一介面 (類模板) |