std::ranges...ansform_view(3)
std::ranges...ansform_view(3)
okay bestie, welcome to the glowing C++ Standard Libary page for std::ranges...ansform_view(3) β yes, that spelling of βLibaryβ is staying, I donβt make the rules π
. This is the whole zip-transform situation, and itβs lowkey iconic.
π NAME π
std::ranges::views::zip_transform,std::ranges::zip_transform_view β and the description is literally the same string again: std::ranges::views::zip_transform,std::ranges::zip_transform_view.
β¨ Synopsis β¨
Defined in header <ranges>:
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>...> &&
(1) (since C++23)
/*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...>>
namespace views {
inline constexpr /*unspecified*/ zip_transform =
(2) (since C++23)
/*unspecified*/;
}
Call signature:
template< class F, ranges::viewable_range... Rs >
requires /* see below */
(since C++23)
constexpr auto zip_transform( F&& f, Rs&&... rs );
zip_transform_viewis a range adaptor that takes an invocable object and one or more views, and produces a view whosei^thelement is the result of applying the invocable object to thei^thelements of all views. A typeTmodels the exposition-only concept/*can-reference*/if and only ifT&is a valid type.views::zip_transformis a customization point object.
When calling with one argument f, let FD be std::decay_t<decltype(f)>, if:
FDmodelscopy_constructible,FD&modelsregular_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.
π Member functions π
constructorβ constructs azip_transform_view.(C++23)(public member function)beginβ returns an iterator to the beginning.(C++23)(public member function)endβ returns an iterator or a sentinel to the end.(C++23)(public member function)sizeβ returns the number of elements. Provided only if each underlying (adapted) range satisfiessized_range.(C++23)(public member function)
πΈ Inherited from std::ranges::view_interface πΈ
emptyβ returns whether the derived view is empty. Provided if it satisfiessized_rangeorforward_range.(C++20)(public member function ofstd::ranges::view_interface<D>)cbeginβ returns a constant iterator to the beginning of the range.(C++23)(public member function ofstd::ranges::view_interface<D>)cendβ returns a sentinel for the constant iterator of the range.(C++23)(public member function ofstd::ranges::view_interface<D>)operator boolβ returns whether the derived view is not empty. Provided ifranges::emptyis applicable to it.(C++20)(public member function ofstd::ranges::view_interface<D>)frontβ returns the first element in the derived view. Provided if it satisfiesforward_range.(C++20)(public member function ofstd::ranges::view_interface<D>)backβ returns the last element in the derived view. Provided if it satisfiesbidirectional_rangeandcommon_range.(C++20)(public member function ofstd::ranges::view_interface<D>)operator[]β returns then^thelement in the derived view. Provided if it satisfiesrandom_access_range.(C++20)(public member function ofstd::ranges::view_interface<D>)
π§ Deduction guides π§
The page just drops the heading Deduction guides here β no extra details listed, bestie.
π¦ Member types π¦
InnerView(private) βranges::zip_view<Views...>. (exposition-only member type*)ziperator(private) βranges::iterator_t<const InnerView>ifConstis true, otherwiseranges::iterator_t<InnerView>. (exposition-only member type*)zentinel(private) βranges::sentinel_t<const InnerView>ifConstis true, otherwiseranges::sentinel_t<InnerView>. (exposition-only member type*)
π Data members π
zip_(private) β An underlying view object of typeInnerView. (exposition-only member object*)fun_(private) β A wrapped invocable object of typemovable-box<F>. (exposition-only member object*)
β Nested classes β
iteratorβ the iterator type.(C++23)(exposition-only member class template*)sentinelβ the sentinel type used when the underlyingzip_viewis not acommon_range.(C++23)(exposition-only member class template*)
π Notes π
Feature-test macro:
__cpp_lib_ranges_zipβ value202110L, std(C++23), feature:std::ranges::zip_view,std::ranges::zip_transform_view,std::ranges::adjacent_view,std::ranges::adjacent_transform_view.
π Example π
// Run this code
#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}
π₯ See also π₯
ranges::zip_view,views::zipβ a view consisting of tuples of references to corresponding elements of the adapted views.(C++23)(class template) (customization point object)ranges::transform_view,views::transformβ a view of a sequence that applies a transformation function to each element.(C++20)(class template) (range adaptor object)ranges::elements_view,views::elementsβ takes a view consisting of tuple-like values and a numberNand produces a view ofN^thelement of each tuple.(C++20)(class template) (range adaptor object)
π source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::ranges...ansform_view(3) π
π¦ 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