Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::reverse_iterator<Iter>::base

      From cppreference.com
      <cpp‎ |iterator‎ |reverse iterator
       
       
      Iterator library
      Iterator concepts
      Iterator primitives
      Algorithm concepts and utilities
      Indirect callable concepts
      Common algorithm requirements
      (C++20)
      (C++20)
      (C++20)
      Utilities
      (C++20)
      Iterator adaptors
      Range access
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++17)(C++20)
      (C++17)
      (C++17)
       
       
      iterator_type base()const;
      (constexpr since C++17)

      Returns the underlying iterator.

      Contents

      [edit]Return value

      current

      [edit]Notes

      The base iterator refers to the element that is next (from theiterator_type perspective) to the element thereverse_iterator is currently pointing to. That is&*(this->base()-1)==&*(*this).

      [edit]Example

      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>; constauto 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';}

      Output:

      *it == 3*r_it == 2*r_it.base() == 3*(r_it.base() - 1) == 20 1 2 3 4 55 4 3 2 1 0

      [edit]See also

      accesses the pointed-to element
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/reverse_iterator/base&oldid=177391"

      [8]ページ先頭

      ©2009-2025 Movatter.jp