std::ranges...p_view::size(3)
π std::ranges::zip_view::size(3) π
okay bestie, welcome to the std::ranges::zip_view::size(3) page from the C++ Standard Library β manual name folded in near the top like a little name tag β¨. The header up there is giving std::ranges...p_view::size(3) and the manual name is spelled C++ Standard Libary in the original (not me, I promise π), but the full NAME is std::ranges::zip_view::size.
πΈ NAME πΈ
std::ranges::zip_view::size β literally std::ranges::zip_view::size, no cap. This is the member that tells you how many elements are in your zip_view π.
β¨ Synopsis β¨
constexpr auto size() (1) (since
C++23)
requires (ranges::sized_range<Views> && ...);
constexpr auto size() const (2) (since
C++23)
requires (ranges::sized_range<const Views> && ...);
It returns the number of elements in the zip_view π«Ά. Itβs provided only if each underlying (adapted) range satisfies sized_range.
Equivalent to:
return std::apply
(
[](auto... sizes)
{
using CT = /*make-unsigned-like-
t*/<std::common_type_t<decltype(sizes)...>>;
return ranges::min({CT(sizes)...});
},
/*tuple-transform*/(ranges::size, views_)
);
π Parameters π
(none)β literally none, zero, zilch. It takes no parameters, bestie π«Ά.
π Return value π
The number of elements β which is the minimum size among all sizes of adapted views. So itβs like the shortest friend in the group chat deciding how many people fit in the pic πβ¨.
π Example π
// Run this code
#include <algorithm>
#include <cassert>
#include <deque>
#include <forward_list>
#include <ranges>
#include <vector>
int main()
{
auto x = std::vector{1, 2, 3, 4, 5};
auto y = std::deque{'a', 'b', 'c'};
auto z = std::forward_list{1., 2.};
auto v1 = std::views::zip(x, y);
assert(v1.size() == std::min(x.size(), y.size()));
assert(v1.size() == 3);
[[maybe_unused]] auto v2 = std::views::zip(x, z);
// auto sz = v2.size(); // Error, v2 does not have size():
static_assert(not std::ranges::sized_range<decltype(z)>);
}
That commented-out line is the whole vibe: v2.size() would be an error because v2 does not have size() π, and the static_assert checks that decltype(z) is not a std::ranges::sized_range.
π¦ 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 π β cute little sign-off for the footer: source/version and date are http://cppreference.com, 2024.06.10, page std::ranges...p_view::size(3). Thatβs the footer folded into a sign-off instead of copied as a line π.
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms