Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::counted_iterator<I>::base

      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)
       
       
      constexprconst I& base()const&noexcept;
      (1)(since C++20)
      constexpr I base()&&;
      (2)(since C++20)

      Returns the underlying base iterator.

      1) Returns a reference to the underlying iterator.
      2) Move constructs the return value from the underlying iterator.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      1) A reference to the underlying iterator.
      2) An iterator move constructed from the underlying iterator.

      [edit]Exceptions

      May throw implementation-defined exceptions.

      [edit]Example

      Run this code
      #include <algorithm>#include <iostream>#include <iterator>#include <type_traits>#include <vector> int main(){std::vector<int> v{0,1,2,3,4}; std::reverse_iterator<std::vector<int>::iterator> reverse{v.rbegin()}; std::counted_iterator counted{reverse,3};     static_assert(std::is_same<        decltype(counted.base()),std::reverse_iterator<std::vector<int>::iterator>const&>{}); std::cout<<"Print with reverse_iterator: ";for(auto r= counted.base(); r!= v.rend();++r)std::cout<<*r<<' ';std::cout<<'\n'; std::cout<<"Print with counted_iterator: ";for(; counted!=std::default_sentinel;++counted)std::cout<< counted[0]<<' ';std::cout<<'\n';}

      Output:

      Print with reverse_iterator: 4 3 2 1 0Print with counted_iterator: 4 3 2

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3391C++20the const version ofbase returns a copy of the underlying iteratorreturns a reference
      LWG 3593C++20the const version ofbase returns a reference but might not be noexceptmade noexcept

      [edit]See also

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

      [8]ページ先頭

      ©2009-2025 Movatter.jp