c++ - map<T, U>.begin() 的迭代器类型是什么

标签 c++

template <class InputIterator, class Distance>
  void advance (InputIterator& it, Distance n);

    InputOutput < Forward < Bidirectional < Random Access

map<int, int> mapInts;
...

std::map<int, int>::iterator it = mapInts.begin();
std::advance (it,5);

问> map.begin 返回的迭代器类型是什么?输入输出、正向、双向?

谢谢

最佳答案

来自Map::begin() documentation

std::map.begin()

Return iterator to beginning Returns an iterator referring to the first element in the map container.

Because map containers keep their elements ordered at all times, begin points to the element that goes first following the container's sorting criterion.

If the container is empty, the returned iterator value shall not be dereferenced.

Return Value: An iterator to the first element in the container.

If the map object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.

Member types iterator and const_iterator are bidirectional iterator types pointing to elements (of type value_type). Notice that value_type in map containers is an alias of pair.

编辑:由@Andy Prowl提供: 根据 C++ 标准 § 23.2.4/6

iterator of an associative container is of the bidirectional iterator category

关于c++ - map<T, U>.begin() 的迭代器类型是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16781915/

相关文章:

c++ - 使用INT32_MAX时无法打印正确答案

c++ - 如何处理线段相交检查中的拐角

c++ - 打破游戏中 GameFlow 和 Controller 之间循环依赖的最佳方法是什么?

c++ - 命名空间范围内的静态关键字无用?

c++ - C++ 中带指针参数的函数

c++ - 如何为 C++ 项目创建文档?

c++ - 我是否必须创建一个对象来调用类方法,或者我可以只输入类名吗?

c++ - Visual Studio 项目已过期

C++ setenv 解析其他变量

c++ - 成员函数无法访问私有(private)变量未在范围类中声明