Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::adjacent_view<V,N>::size

      From cppreference.com
      <cpp‎ |ranges‎ |adjacent view
       
       
      Ranges library
      Range adaptors
       
      std::ranges::adjacent_view
      Member functions
      adjacent_view::size
      Iterator
      Member functions
      Non-member functions
      Sentinel
      Member functions
      Non-member functions
       
      constexprauto size() requiresranges::sized_range<V>;
      (since C++23)
      constexprauto size()const requiresranges::sized_range<const V>;
      (since C++23)

      Returns the number of elements.

      Letbase_ be the underlying view. Equivalent to:

      using SizeType= decltype(ranges::size(base_));using CommonType=ranges::common_type_t<SizeType,std::size_t>;auto size=static_cast<CommonType>(ranges::size(base_));size-=std::min<CommonType>(size, N-1);returnstatic_cast<SizeType>(size);

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      The number of elements, may be0 ifranges::size(base_) is less thanN.

      [edit]Example

      Run this code
      #include <ranges> int main(){constexprstaticauto v={1,2,3,4,5,6}; constexprint width1{4};constexprauto view1{std::views::adjacent<width1>(v)};    static_assert(view1.size()==3);    static_assert(view1.size()==(v.size()- width1+1)); constexprint width2{8};constexprauto view2{std::views::adjacent<width2>(v)};// window is too wide, so view2 has no elements:    static_assert(view2.size()==0);}

      [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/adjacent_view/size&oldid=156863"

      [8]ページ先頭

      ©2009-2025 Movatter.jp