名稱空間
變體
操作

std::indirectly_readable_traits

來自 cppreference.com
 
 
迭代器庫
迭代器概念
迭代器原語
(C++17 中已棄用)
indirectly_readable_traits
(C++20)


演算法概念與工具
間接可呼叫概念
常用演算法要求
(C++20)
(C++20)
(C++20)
工具
(C++20)
迭代器介面卡
範圍訪問
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
定義於標頭檔案 <iterator>
template< class I >
struct indirectly_readable_traits {};
(1) (C++20 起)
template< class T >

struct indirectly_readable_traits<T*> :

    /* cond-value-type */<T> {};
(2) (C++20 起)
template< class I >

    requires std::is_array_v<I>
struct indirectly_readable_traits<I>;

{ using value_type = std::remove_cv_t<std::remove_extent_t<I>>; }
(3) (C++20 起)
template< class T >

struct indirectly_readable_traits<const T> :

    indirectly_readable_traits<T> {};
(4) (C++20 起)
template< /* has-member-value-type */ T >

struct indirectly_readable_traits<T> :

    /* cond-value-type */<typename T::value_type> {};
(5) (C++20 起)
template< /* has-member-element-type */ T >

struct indirectly_readable_traits<T> :

    /* cond-value-type */<typename T::element_type> {};
(6) (C++20 起)
template< /* has-member-value-type */ T >

    requires /* has-member-element-type */<T>

struct indirectly_readable_traits<T> {};
(7) (C++20 起)
template< /* has-member-value-type */ T >

    requires /* has-member-element-type */<T> &&
             std::same_as<std::remove_cv_t<typename T::element_type>,
                          std::remove_cv_t<typename T::value_type>>
struct indirectly_readable_traits<T> :

    /* cond-value-type */<typename T::value_type> {};
(8) (C++20 起)
輔助類和概念
template< class >
struct /* cond-value-type */ {};
(1) (僅作說明*)
template< class T >

    requires std::is_object_v<T>
struct /* cond-value-type */ <T>

{ using value_type = std::remove_cv_t<T>; };
(2) (僅作說明*)
template< class T >

concept /* has-member-value-type */ =

    requires { typename T::value_type; };
(3) (僅作說明*)
template< class T >

concept /* has-member-element-type */ =

    requires { typename T::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)

[編輯] 另請參閱

透過應用運算子*指定型別是間接可讀的
(概念) [編輯]
計算迭代器的關聯型別
(別名模板)[編輯]
提供迭代器屬性的統一介面
(類模板) [編輯]