Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::range

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      Defined in header<ranges>
      template<class T>

      concept range= requires( T& t){
         ranges::begin(t);// equality-preserving for forward iterators
         ranges::end(t);

      };
      (since C++20)

      Therange concept defines the requirements of a type that allows iteration over its elements by providing an iterator and sentinel that denote the elements of the range.

      Contents

      [edit]Semantic requirements

      Given an expressionE such thatdecltype((E)) isT,T modelsrange only if

      [edit]Notes

      A typicalrange class only needs to provide two functions:

      1. A member functionbegin() whose return type modelsinput_or_output_iterator.
      2. A member functionend() whose return type modelssentinel_for<It>, whereIt is the return type ofbegin().

      Alternatively, they can be non-member functions, to be found byargument-dependent lookup.

      [edit]Example

      Run this code
      #include <ranges> // A minimum rangestruct SimpleRange{int* begin();int* end();};static_assert(std::ranges::range<SimpleRange>); // Not a range: no begin/endstruct NotRange{int t{};};static_assert(!std::ranges::range<NotRange>); // Not a range: begin does not return an input_or_output_iteratorstruct NotRange2{void* begin();int* end();};static_assert(!std::ranges::range<NotRange2>); int main(){}

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3915C++20ranges::begin(t) andranges::end(t)
      did not require implicit expression variations
      removed the
      redundant description
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/range&oldid=173903"

      [8]ページ先頭

      ©2009-2025 Movatter.jp