Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::subrange<I,S,K>::prev

      From cppreference.com
      <cpp‎ |ranges‎ |subrange
       
       
      Ranges library
      Range adaptors
       
       
      constexpr subrange prev(std::iter_difference_t<I> n=1)const
          requiresstd::bidirectional_iterator<I>;
      (since C++20)

      Returns a copy of*this whosebegin_ is decremented (or incremented ifn is negative). The actual decrement (or increment) operation is performed byadvance().

      Equivalent to:auto tmp=*this;
      tmp.advance(-n);
      return tmp;
      .

      Contents

      [edit]Parameters

      n - number of decrements of the iterator

      [edit]Return value

      As described above.

      [edit]Notes

      The difference between this function andadvance() is that the latter performs the decrement (or increment) in place.

      [edit]Example

      Run this code
      #include <iterator>#include <list>#include <print>#include <ranges> int main(){std::list list{1,2,3,4,5};    std::ranges::subrange sub{std::next(list.begin(),2),std::prev(list.end(),2)};std::println("{} {} {}", sub, sub.prev(), sub.prev(2));}

      Output:

      [3] [2, 3] [1, 2, 3]

      [edit]See also

      obtains a copy of thesubrange with its iterator advanced by a given distance
      (public member function)[edit]
      advances the iterator by given distance
      (public member function)[edit]
      (C++11)
      decrement an iterator
      (function template)[edit]
      decrement an iterator by a given distance or to a bound
      (algorithm function object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/subrange/prev&oldid=179875"

      [8]ページ先頭

      ©2009-2025 Movatter.jp