Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |ranges‎ |drop view
       
       
      Ranges library
      Range adaptors
       
       
      drop_view() requiresstd::default_initializable<V>=default;
      (1)(since C++20)
      constexprexplicit drop_view( V base,ranges::range_difference_t<V> count);
      (2)(since C++20)

      Constructs adrop_view.

      1) Default constructor.Value-initializes the underlying viewbase_ and initializes the countcount_ to0. After construction,base() returns a copy ofV() andsize() equals to the size of the underlying view.
      2) Initializes the underlying viewbase_ withstd::move(base) and the countcount_ withcount. After construction,base() returns a copy ofbase andsize() returnsranges::size(base)- count if the size ofbase is not less thancount, or0 otherwise.

      [edit]Parameters

      base - the underlying view
      count - number of elements to skip

      [edit]Example

      Run this code
      #include <algorithm>#include <array>#include <iostream>#include <iterator>#include <ranges> int main(){constexprstd::array hi{'H','e','l','l','o',',',' ','C','+','+','2','0'};     std::ranges::for_each(hi,[](constchar c){std::cout<< c;});std::cout<<'\n'; constexprauto n=std::distance(hi.cbegin(), std::ranges::find(hi,'C')); auto cxx= std::ranges::drop_view{hi, n};     std::ranges::for_each(cxx,[](constchar c){std::cout<< c;});std::cout<<'\n';}

      Output:

      Hello, C++20C++20

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3714
      (P2711R1)
      C++20the multi-parameter constructor was not explicitmade explicit
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/drop_view/drop_view&oldid=181227"

      [8]ページ先頭

      ©2009-2026 Movatter.jp