Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::take_view<V>::end

      From cppreference.com
      <cpp‎ |ranges‎ |take view
       
       
      Ranges library
      Range adaptors
       
       
      constexprauto end() requires(!/*simple-view*/<V>);
      (1)(since C++20)
      constexprauto end()const requiresranges::range<const V>;
      (2)(since C++20)

      Returns a sentinel or an iterator representing the end of thetake_view. The end of thetake_view is either one past thecountth element in the underlying range, or the end of the underlying range if the latter has less thancount elements.

      1) Returns atake_view::/*sentinel*/<false>, astd::default_sentinel_t, or aranges::iterator_t<V>.
      2) Returns atake_view::/*sentinel*/<true>, astd::default_sentinel_t, or aranges::iterator_t<const V>.

      Overload(1) does not participate in overload resolution ifV is asimple view (that is, ifV andconst V are views with the same iterator and sentinel types).

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      The result depends on the concepts satisfied by possibly const-qualified underlying view typeBase, that isV for(1) orconst V for(2).

      Letbase_ be the underlying view.

      The underlying view type
      satisfies ...
      random_access_range
      yesno
      sized_rangeyesranges::begin(base_)+
         ranges::range_difference_t<Base_>(this->size())
      std::default_sentinel
      no
      1)/*sentinel*/<false>{ranges::end(base_)}
      2)/*sentinel*/<true>{ranges::end(base_)}

      [edit]Example

      Run this code
      #include <iostream>#include <iterator>#include <list>#include <ranges>#include <type_traits>namespace ranges= std::ranges;namespace views= std::views; int main(){constauto list1={3,1,4,1,5};constauto seq1{list1|views::take(4)};    static_assert(ranges::sized_range<decltype(seq1)> andranges::random_access_range<decltype(seq1)> andstd::is_same_v<decltype(seq1.end()), decltype(list1.end())>);for(auto it= seq1.begin(); it!= seq1.end();++it)std::cout<<*it<<' ';std::cout<<'\n'; std::list list2{2,7,1,8,2};constauto seq2{list2|views::take(4)};    static_assert(ranges::sized_range<decltype(seq2)> and                  notranges::random_access_range<decltype(seq2)> andstd::is_same_v<decltype(seq2.end()),std::default_sentinel_t>);for(auto it= seq2.begin(); it!=std::default_sentinel;++it)std::cout<<*it<<' ';std::cout<<'\n';}

      Output:

      3 1 4 12 7 1 8

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      P2393R1C++20implicit conversions between signed and unsigned integer-class types might failmade explicit

      [edit]See also

      returns an iterator to the beginning
      (public member function)[edit]
      iterator adaptor that tracks the distance to the end of the range
      (class template)[edit]
      (C++20)
      compares a sentinel with an iterator returned fromtake_view::begin
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/take_view/end&oldid=173552"

      [8]ページ先頭

      ©2009-2025 Movatter.jp