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

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

πŸ’– std::ranges::zip_transform_view::size πŸ’–

okay so bestie, this page is from the C++ Standard Libary manual (that spelling is literally the manual name, I'm not fixing it πŸ’…). The header line up top says std::ranges...m_view::size(3), and the page is all about std::ranges::zip_transform_view::size. C++23 girlies, this one's for you ✨

🌸 NAME 🌸

std::ranges::zip_transform_view::size - std::ranges::zip_transform_view::size

✨ Synopsis ✨

constexpr auto size()                                 (1) (since
C++23)
    requires ranges::sized_range</*InnerView*/>;
constexpr auto size() const                           (2) (since
C++23)
    requires ranges::sized_range<const /*InnerView*/>

This one returns the number of elements in the zip_transform_view. It's provided only if each underlying (adapted) range satisfies sized_range β€” yes, every single one, no exceptions πŸ™ˆ

Both numbered overloads, 1 and 2, are equivalent to:

return zip_.size();

πŸŽ€ Parameters πŸŽ€

(none) β€” not a single argument, bestie.

πŸ’œ Return value πŸ’œ

The number of elements, which is the minimum size among all sizes of adapted views. So it's giving "smallest size wins" 🌈

πŸ¦‹ Example πŸ¦‹

// Run this code

#include <algorithm>
#include <cassert>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <ranges>
#include <vector>

int main()
{
    auto x = std::vector{1, 2, 3, 4, 5};
    auto y = std::deque<short>{10, 20, 30};
    auto z = std::forward_list{100., 200.};

    auto v1 = std::views::zip_transform(std::plus{}, x, y);
    assert(v1.size() == std::min(x.size(), y.size()));
    assert(v1.size() == 3);
    for (int i : v1)
        std::cout << i << ' ';
    std::cout << '\n';

    [[maybe_unused]] auto v2 = std::views::zip_transform(std::plus{},
       x, z);
        //  auto sz = v2.size(); // Error: z doesn't have size(), so neither
       does v2
    static_assert(not std::ranges::sized_range<decltype(z)>);
}

πŸ“Ί Output: πŸ“Ί

11 22 33

🌟 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)

okay that's the whole page bestie 🫢 source/version is http://cppreference.com, date is 2024.06.10, and the footer repeats the title std::ranges...m_view::size(3). bye and slay πŸ’…πŸ’–

πŸ“¦ where this page comes from