贡献者: addis
LegacyInputIterator, 只能 single-pass,即遍历一遍(例如 stdin 不能反复从头读)
LegacyForwardIterator, 可以反复遍历。是 preserving,即同一个迭代器的 copy 在其中一个 ++ 后不会失效。
LegacyBidirectionalIterator, 多了 --
LegacyRandomAccessIterator, 多了 +, -, +=, -=, >, >=, <, <=, [] 等算符支持
LegacyContiguousIterator
v.end(),其他的超出范围都是未定义行为。
LegacyForwardIterator。
for (aito &e: v) 基本相当于 for (auto it = v.begin(); it != v.end(); ++it) {auto &e = *it; ...}
std::sort, std::search 等标准算法,还需要定义一些属性(不用的话就不强制)
// Required for standard algorithms:
using iterator_category = std::forward_iterator_tag;
using value_type = T;
using difference_type = std::ptrdiff_t;
using reference = T&;
using pointer = T*;
std::iterator_traits<迭代器类> 获取以上属性。
std::iterator_traits
 
 
 
 
 
 
 
 
 
 
 
友情链接: 超理论坛 | ©小时科技 保留一切权利