Section hub

std::ranges::views::zip_transform, std::ranges::zip_transform_view

  1. zip_transform_view is a range adaptor that takes an invocable object and one or more views, and produces a view whose ith element is the result of applying the invocable object to the ith elements of all views. A type T models the exposition-only concept /can-reference/ if and only if T& is a valid type.

# Declarations

template< std::move_constructible F, ranges::input_range... Views >
requires (ranges::view<Views> && ...) && (sizeof...(Views) > 0) &&
std::is_object_v<F> && std::regular_invocable<
F&, ranges::range_reference_t<Views>...> &&
/*can-reference*/<std::invoke_result_t<
F&, ranges::range_reference_t<Views>...>>
class zip_transform_view
: public ranges::view_interface<zip_transform_view<F, Views...>>

(since C++23)

namespace views {
inline constexpr /*unspecified*/ zip_transform = /*unspecified*/;
}

(since C++23)

Call signature
template< class F, ranges::viewable_range... Rs >
requires /* see below */
constexpr auto zip_transform( F&& f, Rs&&... rs );

(since C++23)

# Notes

Feature-test macro Value Std Feature __cpp_lib_ranges_zip 202110L (C++23) ranges::zip_view,std::ranges::zip_transform_view,ranges::adjacent_view,ranges::adjacent_transform_view

# Example

#include <array>
#include <iostream>
#include <list>
#include <ranges>
#include <vector>
 
void print(auto const rem, auto const& r)
{
    std::cout << rem << '{'; 
    for (char o[]{0,' ',0}; auto const& e : r)
        std::cout << o << e, *o = ',';
    std::cout << "}\n";
}
 
int main()
{
    auto v1 = std::vector<float>{1, 2, 3};
    auto v2 = std::list<short>{1, 2, 3, 4};
    auto v3 = std::to_array({1, 2, 3, 4, 5});
 
    auto add = [](auto a, auto b, auto c) { return a + b + c; };
 
    auto sum = std::views::zip_transform(add, v1, v2, v3);
 
    print("v1:  ", v1);
    print("v2:  ", v2);
    print("v3:  ", v3);
    print("sum: ", sum);
}

# See also

This hub groups the ranges library by user task rather than by raw reference tree shape. View types and adaptor objects are presented as the same conceptual item.

Core adapters

Start here for the adapters most people reach for first when building pipelines.

Utility views

These adapt shape, ownership, or projection rather than representing the “headline” pipeline steps.

New in C++23 / C++26

Newer adapters, kept as a compact scan list with only standard badges.

All entities by category

A lighter-weight index of the full ranges surface, grouped by conceptual task instead of raw page-tree names.

74 entities