Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::take_view<V>::begin

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

      Returns an iterator to the first element of thetake_view.

      1) Returns astd::counted_iterator or aranges::iterator_t<V>.
      2) Returns astd::counted_iterator 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, which isV for(1) orconst V for(2).

      Letbase_ be the underlying view,count_ be the underlying counter (equals to0 iftake_view was default initialized).

      The underlying view type
      satisfies ...
      random_access_range
      yes no
      sized_range yesranges::begin(base_)std::counted_iterator(ranges::begin(base_),
         ranges::range_difference_t<Base_>(this->size()))
      nostd::counted_iterator(ranges::begin(base_), count_)

      [edit]Example

      Run this code
      #include <concepts>#include <forward_list>#include <iostream>#include <ranges>#include <string_view>#include <type_traits>usingnamespace std::literals; int main(){{staticconstexprauto v={"∀x"sv,"∃y"sv,"ε"sv,"δ"sv};auto view= std::ranges::take_view(v,8);auto iter= view.begin();std::cout<<*iter<<'\n';        static_assert(            std::ranges::sized_range<decltype(v)> and            std::ranges::random_access_range<decltype(v)> andstd::is_same_v<decltype(iter), decltype(std::ranges::begin(v))>);} {std::forward_list v={"Ax"sv,"Ey"sv,"p"sv,"q"sv};auto view= std::ranges::take_view(v,8);auto iter= view.begin();std::cout<<*iter<<'\n';        static_assert(            not std::ranges::sized_range<decltype(v)> and            not std::ranges::random_access_range<decltype(v)> andstd::is_same_v<decltype(iter),std::counted_iterator<std::forward_list<std::string_view>::iterator>>);}}

      Output:

      ∀xAx

      [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 or a sentinel to the end
      (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/begin&oldid=173551"

      [8]ページ先頭

      ©2009-2025 Movatter.jp