Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:ReversibleContainer

      From cppreference.com
      <cpp‎ |named req
       
       
      C++ named requirements
       

      AReversibleContainer is aContainer that has iterators that meet the requirements of eitherLegacyBidirectionalIterator orLegacyRandomAccessIterator. Such iterators allow aReversibleContainer to be iterated over in reverse.

      Contents

      [edit]Requirements

      A type satisfiesReversibleContainer if it satisfiesContainer, its iterator type belongs to the bidirectional or random accessiterator categories and, given the following types and values, the semantic and complexity requirements in the tables below are satisfied:

      Type Definition
      X anReversibleContainer type
      T thevalue_type ofX
      Value Definition
      a a value of typeX

      [edit]Types

      NameTypeRequirements
      typename X::reverse_iteratorstd::reverse_iterator<X::iterator>an iterator type whosevalue type isT
      typename X::const_reverse_iterator std::reverse_iterator<X::const_iterator> a constant iterator type whosevalue type isT

      [edit]Expressions

      The typesreverse_iterator andconst_reverse_iterator in the following table denotetypename X::reverse_iterator andtypename X::const_reverse_iterator respectively.

      ExpressionTypeSemantics Complexity 
      a.rbegin()reverse_iterator
      const_reverse_iterator for constanta
      reverse_iterator(a.end())Constant
      a.rend()reverse_iterator
      const_reverse_iterator for constanta
      reverse_iterator(a.begin())Constant
      a.crbegin()const_reverse_iteratorconst_cast<const X&>(a).rbegin()Constant
      a.crend()const_reverse_iteratorconst_cast<const X&>(a).rend()Constant

      [edit]Library types

      The following standard library types satisfyReversibleContainer requirements:

      (C++11)
      fixed-sized inplace contiguous array
      (class template)[edit]
      double-ended queue
      (class template)[edit]
      doubly-linked list
      (class template)[edit]
      resizable contiguous array
      (class template)[edit]
      resizable, fixed capacity, inplace contiguous array
      (class template)[edit]
      collection of key-value pairs, sorted by keys, keys are unique
      (class template)[edit]
      collection of key-value pairs, sorted by keys
      (class template)[edit]
      collection of unique keys, sorted by keys
      (class template)[edit]
      collection of keys, sorted by keys
      (class template)[edit]

      [edit]Example

      The following example iterates over avector (which haslegacy random-access iterators) in reverse.

      Run this code
      #include <iostream>#include <vector> int main(){std::vector<int> v={3,1,4,1,5,9}; for(std::vector<int>::const_reverse_iterator i{v.crbegin()}; i!= v.crend();++i)std::cout<<*i<<' ';std::cout<<'\n';}

      Output:

      9 5 1 4 1 3

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2105C++98typename X::const_reverse_iterator was
      required to be an iterator type of value typeconst T
      required to be a constant
      iterator type of value typeT
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/ReversibleContainer&oldid=178188"

      [8]ページ先頭

      ©2009-2025 Movatter.jp