Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::make_reverse_iterator

      From cppreference.com
      <cpp‎ |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)
       
      Defined in header<iterator>
      template<class Iter>
      std::reverse_iterator<Iter> make_reverse_iterator( Iter i);
      (since C++14)
      (constexpr since C++17)

      make_reverse_iterator is a convenience function template that constructs astd::reverse_iterator for the given iteratori (which must be aLegacyBidirectionalIterator) with the type deduced from the type of the argument.

      Contents

      [edit]Parameters

      i - iterator to be converted to reverse iterator

      [edit]Return value

      std::reverse_iterator<Iter>(i)

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_make_reverse_iterator201402L(C++14)std::make_reverse_iterator

      [edit]Example

      Run this code
      #include <algorithm>#include <iostream>#include <iterator>#include <vector> int main(){std::vector<int> v{1,3,10,8,22}; std::sort(v.begin(), v.end());std::copy(v.begin(), v.end(),std::ostream_iterator<int>(std::cout,", "));std::cout<<'\n'; std::copy(std::make_reverse_iterator(v.end()),              std::make_reverse_iterator(v.begin()),std::ostream_iterator<int>(std::cout,", "));std::cout<<'\n';}

      Output:

      1, 3, 8, 10, 22,22, 10, 8, 3, 1,

      [edit]See also

      iterator adaptor for reverse-order traversal
      (class template)[edit]
      returns a reverse iterator to the beginning of a container or array
      (function template)[edit]
      (C++14)
      returns a reverse end iterator for a container or array
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/make_reverse_iterator&oldid=177531"

      [8]ページ先頭

      ©2009-2025 Movatter.jp