std::reverse_iterator<Iter>::base
来自cppreference.com
< cpp | iterator | reverse iterator
iterator_type base() const; |
(C++17 前) | |
constexpr iterator_type base() const; |
(C++17 起) | |
返回底层迭代器。即 std::reverse_iterator(it).base() == it 。
底层迭代器指代(相对于 std::reverse_iterator::iterator_type 的) reverse_iterator
当前所指元素的下一个元素。即 &*(rit.base() - 1) == &*rit 。
参数
(无)
返回值
底层迭代器。
异常
可能抛出实现定义的异常。
示例
运行此代码
#include <iostream> #include <iterator> #include <vector> int main() { std::vector<int> v = { 0, 1, 2, 3, 4, 5 }; using RevIt = std::reverse_iterator<std::vector<int>::iterator>; { const auto it = v.begin() + 3; RevIt r_it(it); std::cout << "*it == " << *it << ", *r_it.base() == " << *r_it.base() << '\n' << "*r_it == " << *r_it <<", *(r_it.base()-1) == " << *(r_it.base()-1) << "\n"; } { RevIt r_end(v.begin()); RevIt r_begin(v.end()); for (auto it = r_end.base(); it != r_begin.base(); ++it) { std::cout << *it << " "; } std::cout << "\n"; } }
输出:
*it == 3, *r_it.base() == 3 *r_it == 2, *(r_it.base()-1) == 2 0 1 2 3 4 5
参阅
访问被指向的元素 (公开成员函数) |