std::ranges...k_view::size(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ NAME πŸŽ€

std::ranges::chunk_view::size - std::ranges::chunk_view::size

okay so welcome to the std::ranges::chunk_view::size page πŸ’–. The header/manual-name situation is std::ranges...k_view::size(3) from the C++ Standard Libary (yes, β€œLibary” β€” that's the manual's spelling, not a typo I'm claiming as my own πŸ™ˆ). We're keeping every fact, just with main-character energy. πŸ’…

✨ Synopsis ✨

constexpr auto size() requires ranges::sized_range<V>;
  • (1) β€” since C++23
constexpr auto size() const requires ranges::sized_range<const V>;
  • (2) β€” since C++23

okay so what does it do? It returns the number of elements. That number is the smallest integer value that is not less than the quotient of dividing the size of the underlying view base_ by the underlying data member n_, which holds the number passed to the constructor (0 if default constructed). No cap, it's giving exact div-ceil behavior. Equivalent to:

return __to_unsigned_like(__div_ceil(ranges::distance(base_), n_));

πŸ’– Parameters πŸ’–

(none) β€” zero parameters, bestie. Not a single one. 🫢

πŸŽ€ Return value πŸŽ€

The number of elements. That's the whole return value. Iconic. πŸ‘‘

πŸ¦‹ Example πŸ¦‹

// Run this code

#include <ranges>

int main()
{
    constexpr static auto v = {1, 2, 3, 4, 5};
    constexpr auto w{ std::ranges::chunk_view(v, 2) };
    static_assert(w.size() == (5 / 2 + (5 % 2 ? 1 : 0)));
}

🌈 See also 🌈

  • ranges::size β€” returns an integer equal to the size of a range (C++20) (customization point object)
  • ranges::ssize β€” returns a signed integer equal to the size of a range (C++20) (customization point object)

mwah πŸ’‹ β€” this page came from http://cppreference.com, dated 2024.06.10, and its footer name is std::ranges...k_view::size(3). 🫢

πŸ“¦ where this page comes from