Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::subrange<I,S,K>::size

      From cppreference.com
      <cpp‎ |ranges‎ |subrange
       
       
      Ranges library
      Range adaptors
       
       
      constexpr/*make-unsigned-like-t*/<std::iter_difference_t<I>> size()const
          requires(K== ranges::subrange_kind::sized);
      (since C++20)

      Obtains the number of elements in thesubrange:

      For the definition of/*make-unsigned-like-t*/, seemake-unsigned-like-t .

      [edit]Return value

      As described above.

      [edit]Example

      Run this code
      #include <functional>#include <iostream>#include <ranges>#include <utility> int main(){constauto v={2,2,2,7,1,1,1,1,8,2,2,2,2,2}; // the value type of views::chunk_by is the ranges::subrange auto to_pair=[](auto sub){returnstd::make_pair(sub[0], sub.size());};/* ^^^^ */auto pairs= v| std::views::chunk_by(std::equal_to{})| std::views::transform(to_pair); for(auto x: pairs bitor std::views::keys)std::cout<< x<<' ';std::cout<<'\n';for(auto x: pairs bitor std::views::values)std::cout<< x<<' ';std::cout<<'\n';}

      Output:

      2 7 1 8 23 1 4 1 5

      [edit]See also

      checks whether thesubrange is empty
      (public member function)[edit]
      (C++17)(C++20)
      returns the size of a container or array
      (function template)[edit]
      returns an integer equal to the size of a range
      (customization point object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/subrange/size&oldid=176909"

      [8]ページ先頭

      ©2009-2025 Movatter.jp