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 << '\n' << "*r_it == " << *r_it << '\n' << "*r_it.base() == " << *r_it.base() << '\n' << "*(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'; for (auto it = r_begin; it != r_end; ++it) std::cout << *it << ' '; std::cout << '\n'; }
输出
*it == 3 *r_it == 2 *r_it.base() == 3 *(r_it.base()-1) == 2 0 1 2 3 4 5 5 4 3 2 1 0
[编辑] 另请参见
访问指向的元素 (公有成员函数) |