std::reverse_iterator<Iter>::base

来自cppreference.com
 
 
迭代器库
迭代器概念
迭代器原语
算法概念与工具
间接可调用概念
常用算法要求
工具
迭代器适配器
流迭代器
迭代器定制点
迭代器操作
(C++11)
(C++11)
范围访问
(C++11)(C++14)
(C++11)(C++14)
(C++17)(C++20)
(C++14)(C++14)
(C++14)(C++14)
(C++17)
(C++17)
 
 
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

参阅

访问被指向的元素
(公开成员函数)