【发布时间】:2020-07-11 11:03:58
【问题描述】:
C++20 为标准库中不同类型的迭代器(输入、输出、前向、双向、随机访问等)引入了适当的概念。
虽然这些类型的原始命名要求根本没有提到 the iterator tags from std::iterator_traits,但新的 C++20 概念明确要求它们。例如参见input_iterator 概念 ([iterator.concept.input]):
template<class I>
concept input_iterator =
input_or_output_iterator<I> &&
indirectly_readable<I> &&
requires { typename ITER_CONCEPT(I); } &&
derived_from<ITER_CONCEPT(I), input_iterator_tag>;
请注意最后一行中对迭代器标记的检查。所有迭代器概念都会检查相应的标签,except output iterator。 输出迭代器在这方面一直很特别,since the early days of the Ranges TS:
与 C++ 标准中的输出迭代器要求不同, Ranges TS 中的 OutputIterator 不需要迭代器 定义类别标签。
对输出迭代器进行这种特殊处理的原因是什么?
【问题讨论】:
标签: c++ c++20 c++-concepts