std::ranges::views::zip_transform, std::ranges::zip_transform_view - cppreference.com
From cppreference.com
| Defined in header |
||
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...>> |
(1) | (since C++23) |
namespace views { inline constexpr /*unspecified*/ zip_transform = /*unspecified*/; } |
(2) | (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) | |
1) zip_transform_view is a range adaptor that takes an invocable object and one or more
, 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.
2) views::zip_transform is a customization point object.
When calling with one argument f, let FD be std::decay_t<decltype(f)>, if:
FDmodels copy_constructible,FD&models regular_invocable, andstd::invoke_result_t<FD&>is an object type,
then views::zip_transform(f) is expression-equivalent to ((void)f, auto(views::empty<std::decay_t<std::invoke_result_t<FD&>>>)). Otherwise, the call to views::zip_transform is ill-formed.
When calling with more than one arguments f and rs..., views::zip_transform(f, rs...) is expression-equivalent to ranges::zip_transform_view(f, rs...).
zip_transform_view models the concepts random_access_range, bidirectional_range, forward_range, input_range, common_range, and sized_range when the underlying ranges::zip_view<Views...> models respective concepts.
Customization point objects
The name views::zip_transform denotes a customization point object, which is a const function object of a literal semiregular class type. See CustomizationPointObject for details.
Member functions
constructs a zip_transform_view (public member function) [edit] | |
| returns an iterator to the beginning (public member function) [edit] | |
| returns an iterator or a sentinel to the end (public member function) [edit] | |
| returns the number of elements, provided only if each underlying (adapted) range satisfies sized_range (public member function) [edit] | |
Inherited from ranges::view_interface | |
| returns whether the derived view is empty, provided only if it satisfies sized_range or forward_range (public member function of std::ranges::view_interface<D>) [edit]
| |
(C++23) |
returns a constant iterator to the beginning of the range (public member function of std::ranges::view_interface<D>) [edit]
|
(C++23) |
returns a sentinel for the constant iterator of the range (public member function of std::ranges::view_interface<D>) [edit]
|
| returns whether the derived view is not empty, provided only if ranges::empty is applicable to it (public member function of std::ranges::view_interface<D>) [edit]
| |
| returns the first element in the derived view, provided if it satisfies forward_range (public member function of std::ranges::view_interface<D>) [edit]
| |
| returns the last element in the derived view, provided only if it satisfies bidirectional_range and common_range (public member function of std::ranges::view_interface<D>) [edit]
| |
returns the nth element in the derived view, provided only if it satisfies random_access_range (public member function of std::ranges::view_interface<D>) [edit]
| |
Deduction guides
Member types
| Type | Definition |
InnerView (private)
|
ranges::zip_view<Views...>.(exposition-only member type*) |
ziperator (private)
|
|
zentinel (private)
|
|
Data members
| Member | Description |
InnerView zip_ (private)
|
an underlying view object (exposition-only member object*) |
movable-box<F> fun_ (private)
|
a wrapped invocable object (exposition-only member object*) |
Nested classes
| the iterator type (exposition-only member class template*) | |
the sentinel type used when the underlying zip_view is not a common_range(exposition-only member class template*) |
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); }
Output:
v1: {1, 2, 3}
v2: {1, 2, 3, 4}
v3: {1, 2, 3, 4, 5}
sum: {3, 6, 9}