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 返回的迭代器类型是什么?输入输出、正向、双向?
谢谢
最佳答案
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/