Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      operator+(std::counted_iterator)

      From cppreference.com
      <cpp‎ |iterator‎ |counted 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)
       
       
      friendconstexpr counted_iterator operator+(

         std::iter_difference_t<I> n,const counted_iterator& x)

              requiresstd::random_access_iterator<I>;
      (since C++20)

      Returns an iterator adaptor which is advanced byn. The behavior is undefined ifn is greater than the length recorded withinx (i.e. ifx+ n result in undefined behavior).

      This function is not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup when std::counted_iterator<I> is an associated class of the arguments.

      Contents

      [edit]Parameters

      n - the number of positions to increment the iterator
      x - the iterator adaptor to increment

      [edit]Return value

      An iterator adaptor equal tox+ n.

      [edit]Example

      Run this code
      #include <iostream>#include <iterator>#include <list>#include <vector> int main(){std::vector v{0,1,2,3,4,5};std::counted_iterator<std::vector<int>::iterator> p{v.begin()+1,4};std::cout<<"*p:"<<*p<<", count:"<< p.count()<<'\n';std::counted_iterator<std::vector<int>::iterator> q{2+ p};std::cout<<"*q:"<<*q<<", count:"<< q.count()<<'\n'; std::list l{6,7,8,9};std::counted_iterator<std::list<int>::iterator> r{l.begin(),3};std::cout<<"*r:"<<*r<<", count:"<< r.count()<<'\n';//  auto s{2 + r}; // error: the underlying iterator does// not model std::random_access_iterator}

      Output:

      *p:1, count:4*q:3, count:2*r:6, count:3

      [edit]See also

      advances or decrements thecounted_iterator
      (public member function)[edit]
      (C++20)
      computes the distance between two iterator adaptors
      (function template)[edit]
      computes the signed distance to the end
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/counted_iterator/operator%2B&oldid=159841"

      [8]ページ先頭

      ©2009-2025 Movatter.jp