Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::input_iterator

      From cppreference.com
      <cpp‎ |iterator
       
       
      Iterator library
      Iterator concepts
      input_iterator
      (C++20)

      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)
       
      Defined in header<iterator>
      template<class I>

          concept input_iterator=
             std::input_or_output_iterator<I>&&
             std::indirectly_readable<I>&&
              requires{typename/*ITER_CONCEPT*/<I>;}&&

             std::derived_from</*ITER_CONCEPT*/<I>,std::input_iterator_tag>;
      (since C++20)

      Theinput_iterator concept is a refinement ofinput_or_output_iterator, adding the requirement that the referenced values can be read (viaindirectly_readable) and the requirement that the iterator concept tag be present.

      Contents

      [edit]Iterator concept determination

      Definition of this concept is specified via an exposition-only alias template/*ITER_CONCEPT*/.

      In order to determine/*ITER_CONCEPT*/<I>, letITER_TRAITS<I> denoteI if the specializationstd::iterator_traits<I> is generated from the primary template, orstd::iterator_traits<I> otherwise:

      • IfITER_TRAITS<I>::iterator_concept is valid and names a type,/*ITER_CONCEPT*/<I> denotes the type.
      • Otherwise, ifITER_TRAITS<I>::iterator_category is valid and names a type,/*ITER_CONCEPT*/<I> denotes the type.
      • Otherwise, ifstd::iterator_traits<I> is generated from the primary template,/*ITER_CONCEPT*/<I> denotesstd::random_access_iterator_tag.
        (That is,std::derived_from</*ITER_CONCEPT*/<I>,std::input_iterator_tag> is assumed to betrue.)
      • Otherwise,/*ITER_CONCEPT*/<I> does not denote a type and results in a substitution failure.

      [edit]Notes

      Unlike theLegacyInputIterator requirements, theinput_iterator concept does not requireequality_comparable, since input iterators are typically compared with sentinels.

      [edit]Example

      A minimum input iterator.

      #include <cstddef>#include <iterator> class SimpleInputIterator{public:using difference_type=std::ptrdiff_t;using value_type=int; int operator*()const;     SimpleInputIterator& operator++();void operator++(int){++*this;}}; static_assert(std::input_iterator<SimpleInputIterator>);

      [edit]See also

      specifies that objects of a type can be incremented and dereferenced
      (concept)[edit]
      specifies that aninput_iterator is a forward iterator, supporting equality comparison and multi-pass
      (concept)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/input_iterator&oldid=183121"

      [8]ページ先頭

      ©2009-2025 Movatter.jp