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
是未定义的。
- 如果
- 然后,
V
从C
确定如下- 如果
C
是未定义的,或者C
不是 对象类型,则V
是未定义的。 - 否则,
V
是 cv 非限定的C
。
- 如果
[编辑] 注释
value_type
旨在与诸如迭代器之类的 indirectly_readable
类型一起使用。它不适用于范围。
[编辑] 示例
本节尚不完整 原因:没有示例 |
[编辑] 缺陷报告
以下行为变更缺陷报告已追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
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) |
计算迭代器的关联类型 (别名模板) |
为迭代器的属性提供统一的接口 (类模板) |