Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::drop_view<V>::begin

      From cppreference.com
      <cpp‎ |ranges‎ |drop view
       
       
      Ranges library
      Range adaptors
       
       
      constexprauto begin()

          requires(!(/*simple-view*/<V>&&
                       ranges::random_access_range<const V>&&

                       ranges::sized_range<const V>));
      (1)(since C++20)
      constexprauto begin()const

          requiresranges::random_access_range<const V>&&

                   ranges::sized_range<const V>;
      (2)(since C++20)

      Returns an iterator to the first element of thedrop_view, that is, an iterator to theNth element of the underlying view, or to the end of the underlying view if it has less thanN elements.

      IfV is not arandom_access_range or asized_range, in order to provide the amortized constant time complexity required by therange concept, the overload(1) caches the result within the underlyingcache_ object for use on subsequent calls.

      Contents

      [edit]Return value

      ranges::next(ranges::begin(base_), count_,ranges::end(base_)).

      [edit]Example

      Run this code
      #include <array>#include <concepts>#include <iostream>#include <iterator>#include <ranges> void println(std::ranges::rangeautoconst& range){for(autoconst& elem: range)std::cout<< elem;std::cout<<'\n';} int main(){std::array hi{'H','e','l','l','o',',',' ','C','+','+','2','0','!'};    println(hi); constauto pos=std::distance(hi.begin(), std::ranges::find(hi,'C'));auto cxx= std::ranges::drop_view{hi, pos};std::cout<<"*drop_view::begin() == '"<<*cxx.begin()<<"'\n";//  *cxx.begin() = 'c'; // undefined: 'views' are to be used as observers    println(cxx);}

      Output:

      Hello, C++20!*drop_view::begin() == 'C'C++20!

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3482C++20the const overload can be called with unsized rangesthe const overload requiressized_range

      [edit]See also

      returns an iterator or a sentinel to the end
      (public member function)[edit]
      returns an iterator to the beginning of a range
      (customization point object)[edit]
      returns a sentinel indicating the end of a range
      (customization point object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/drop_view/begin&oldid=181229"

      [8]ページ先頭

      ©2009-2025 Movatter.jp