Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:LegacyIterator

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

      TheLegacyIterator requirements describe types that can be used to identify and traverse the elements of a container.

      LegacyIterator is the base set of requirements used by other iterator types:LegacyInputIterator,LegacyOutputIterator,LegacyForwardIterator,LegacyBidirectionalIterator, andLegacyRandomAccessIterator. Iterators can be thought of as an abstraction of pointers.

      All the categories of iterators require only those functions that are realizable for a given category in constant time (amortized). Therefore, requirement tablesand concept definitions(since C++20) for the iterators do not specify complexity.

      Contents

      [edit]Requirements

      The typeIt satisfiesLegacyIterator if

      • The typeIt satisfiesCopyConstructible, and
      • The typeIt satisfiesCopyAssignable, and
      • The typeIt satisfiesDestructible, and
      • The typeIt satisfiesSwappable, and
      • std::iterator_traits<It> has member typedefs:value_type,(until C++20)difference_type,reference,pointer, anditerator_category, and
      • Givenr, an lvalue of typeIt, the following expressions must be valid and have their specified effects:
      ExpressionReturn TypePrecondition
      *runspecifiedr isdereferenceable
      ++rIt&r isincrementable (the behavior of the expression++r is defined)

      Concept

      For the definition ofstd::iterator_traits, the following exposition-only concept is defined.

      template<class I>

      concept __LegacyIterator=
          requires(I i)
         {
             {  *i}-> __Referenceable;
             {  ++i}->std::same_as<I&>;
             {*i++}-> __Referenceable;

         }&&std::copyable<I>;

      where the exposition-only concept__Referenceable<T> is satisfied if and only ifT& is a valid type (in particular,T must not bevoid).

      (since C++20)

      [edit]Notes

      Note on terminology: The following table shows the names used on this site and corresponding C++ Standard names (with the same meaning).The "Legacy" (and “Cpp17”) prefix emphasizes compatibility with pre-C++20 standards and is used to distinguish these requirements from the newiterator concepts introduced with C++20.

      cppreference namesC++ Standard namesC++20 iterator concepts
      LegacyIteratorCpp17Iteratorinput_or_output_iterator
      LegacyInputIteratorCpp17InputIteratorinput_iterator
      LegacyOutputIteratorCpp17OutputIteratoroutput_iterator
      LegacyForwardIteratorCpp17ForwardIteratorforward_iterator
      LegacyBidirectionalIteratorCpp17BidirectionalIteratorbidirectional_iterator
      LegacyRandomAccessIteratorCpp17RandomAccessIteratorrandom_access_iterator
      LegacyContiguousIterator[1]contiguous_iterator
      1. LegacyContiguousIterator category was only formally specified in C++17, but the iterators ofstd::vector,std::basic_string,std::array, andstd::valarray, as well as pointers into C arrays are often treated as a separate category in pre-C++17 code.

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2437C++98*r is required to bereferencenot required for output iterators
      LWG 3420C++20the exposition-only concept checkscopyable firstcopyable is checked only if the requires-expression yields true

      [edit]See also

      specifies that objects of a type can be incremented and dereferenced
      (concept)[edit]
      Iterator library provides definitions for iterators, iterator traits, adaptors, and utility functions
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/Iterator&oldid=182604"

      [8]ページ先頭

      ©2009-2025 Movatter.jp