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 限定,那么V是无 const 限定的T的关联值类型。 - 否则,如果
T是数组类型,那么V是无 cv 限定的数组元素类型。 - 否则,首先确定条件值类型
C:
-
- 如果
T是指针类型,那么C是被指向的类型。 - 否则,如果
T具有嵌套类型value_type和element_type:
-
- 如果两个嵌套类型相同(不考虑 cv 限定),那么
C是typename T::value_type。 - 否则
C未定义。
- 如果两个嵌套类型相同(不考虑 cv 限定),那么
- 否则,如果
T只有嵌套类型value_type而没有element_type,那么C是typename T::value_type。 - 否则,如果
T只有嵌套类型element_type而没有value_type,那么C是typename T::element_type。 - 否则
C未定义。
- 如果
- 然后按以下方式从
C确定V:- 如果
C未定义,或者C不是对象类型,那么V未定义。 - 否则
V是无 cv 限定的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)
|
计算迭代器的关联类型 (别名模板) |
| 为迭代器各项性质提供统一接口 (类模板) |