Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::enumerate_view<V>::size

      From cppreference.com
      <cpp‎ |ranges‎ |enumerate view
       
       
      Ranges library
      Range adaptors
       
      std::ranges::enumerate_view
      Member functions
      enumerate_view::size
      Deduction guides
      Nested classes
      Iterator
      Sentinel
       
      constexprauto size() requiresranges::sized_range<V>;
      (1)(since C++23)
      constexprauto size()const requiresranges::sized_range<const V>;
      (2)(since C++23)

      Returns the number of elements. Equivalent toreturnranges::size(base_);, wherebase_ is the underlying view.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      The number of elements.

      [edit]Example

      Run this code
      #include <cassert>#include <forward_list>#include <ranges>#include <string_view> int main(){constexprstaticauto v1={1,2,3,4,5};constexprauto ev1{v1| std::views::enumerate};    static_assert(ev1.size()==5);    static_assert(std::ranges::sized_range<decltype(v1)>); auto v2=std::forward_list{1,2,3,4,5};auto ev2{v2| std::views::enumerate};    static_assert(not std::ranges::sized_range<decltype(v2)>);// auto size = ev2.size(); // Error: v2 is not a sized rangeassert(std::ranges::distance(v2)==5);// OK, distance does not require sized// range, but has O(N) complexity here}

      [edit]See also

      returns an integer equal to the size of a range
      (customization point object)[edit]
      returns a signed integer equal to the size of a range
      (customization point object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/enumerate_view/size&oldid=156878"

      [8]ページ先頭

      ©2009-2025 Movatter.jp