std::reverse_iterator<Iter>::base
提供: cppreference.com
<tbody>
</tbody>
iterator_type base() const; |
(C++17未満) | |
constexpr iterator_type base() const; |
(C++17以上) | |
ベースとなるイテレータを返します。 つまり std::reverse_iterator(it).base() == it です。
ベースとなるイテレータは reverse_iterator が現在指している要素の次 (std::reverse_iterator::iterator_type の視点で) の要素を参照します。 つまり、 &*(rit.base() - 1) == &*rit です。
引数
(なし)
戻り値
ベースとなるイテレータ。
例外
(なし)
例
Run this code
#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
関連項目
| イテレータの指す先の要素にアクセスします (パブリックメンバ関数) |