std::reverse_iterator是一种迭代器适配器,它反转给定迭代器的方向,该迭代器必须至少是老式双向迭代器(LegacyBidirectionalIterator)或实现bidirectional_iterator(C++20 起)。换言之,提供双向迭代器时,std::reverse_iterator产生一个新的迭代器,它从底层的双向迭代器所定义的序列的末尾移动到开端。
cppreference.com 创建账户 页面 讨论 变换 查看 编辑 历史 std::reverse_iterator<Iter>::baseC++ 迭代器库 std::reverse_iterator iterator_type base() const; (C++17 起为 constexpr) 返回底层迭代器。 返回值current 注解底层迭代器指代(相对于 iterator_type 的)reverse_iterator 当前所指元素的下一个...
看cplusplus和cppreference的上的解释 Notice however that when an iterator is reversed, the reversed version does not point to the same element in the range, but to the one preceding it. This is so, in order to arrange for the past-the-end element of a range: An iterator pointing to a ...
Return value std::reverse_iterator<Iter>(i) Notes Feature-testmacroValueStdFeature __cpp_lib_make_reverse_iterator201402L(C++14)std::make_reverse_iterator Example Run this code #include <algorithm>#include <iostream>#include <iterator>#include <vector>intmain(){std::vector<int>v{1,3,10,8...
The base iterator refers to the element that is next (from thestd::reverse_iterator::iterator_typeperspective) to the element thereverse_iteratoris currently pointing to. That is&*(rit.base()-1)==&*rit. Parameters (none) Return value ...
typename std::iterator_traits<Iter>::value_type, typename std::iterator_traits<Iter>::difference_type, typename std::iterator_traits<Iter>::pointer, typename std::iterator_traits<Iter>::reference > (C++17 前) template< class Iter > class reverse_iterator; (C++17 起) std...
typenamestd::iterator_traits<Iter>::reference> (C++17 前) template<classIter> classreverse_iterator; (C++17 起) std::reverse_iterator是一个反转给定迭代器方向的迭代器适配器。换言之,提供双向迭代器时,std::reverse_iterator产生一个新的迭代器,它从底层的双向迭代器所定义的序列的末尾移动到开端。
reference operator*() const; 返回值由reverse_iterator 寻址的元素的值。备注运算符返回 *( current - 1)。示例C++ 复制 // reverse_iterator_op_ref.cpp // compile with: /EHsc #include <iterator> #include <algorithm> #include <vector> #include <iostream> int main( ) { using namespace std;...
typename std::iterator_traits<Iter>::reference > (C++17 前) template< class Iter >class reverse_iterator; (C++17 起)std::reverse_iterator 是一个反转给定必须至少是遗留双向迭代器 (LegacyBidirectionalIterator) 或实现 bidirectional_iterator (C++20 起)的迭代器方向的适配器。换言之,提供双向迭代器时,...
// reverse_iterator_reverse_iterator.cpp // compile with: /EHsc #include <iterator> #include <algorithm> #include <vector> #include <iostream> int main( ) { using namespace std; int i; vector<int> vec; for ( i = 1 ; i < 6 ; ++i ) ...