| ||||||||||||||||||||||
| Range primitives | |||||||
| |||||||
| Range concepts | |||||||||||||||||||
| |||||||||||||||||||
| Range factories | |||||||||
| |||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Helper items | |||||||||||||||||
| |||||||||||||||||
| Member functions | ||||
| Iterator | ||||
| Member functions | ||||
| Non-member functions | ||||
| Sentinel | ||||
| Member functions | ||||
| Non-member functions | ||||
Defined in header <ranges> | ||
template<ranges::forward_range V,std::move_constructible F,std::size_t N> requiresranges::view<V>&&(N>0)&&std::is_object_v<F>&& | (1) | (since C++23) |
namespace views{ template<std::size_t N> | (2) | (since C++23) |
namespace views{ inlineconstexprauto pairwise_transform= adjacent_transform<2>; | (3) | (since C++23) |
Call signature | ||
template<ranges::viewable_range R,class F> requires/* see below */ | (since C++23) | |
template<class F> constexpr/*range adaptor closure*/ adjacent_transform<N>( F&& fun); | (since C++23) | |
adjacent_transform_view is a range adaptor that takes aview and an invocable objectfun, and produces aview whoseith element is a value that is the result of applyingfun to each element in[i, i+ N) of the original view.F always hasarityN.S be the size of the original view. Then the size of produced view is:N, the expressionviews::adjacent_transform<N>(e, f) isexpression-equivalent to:N is equal to0 anddecltype((e)) modelsforward_range (except that the evaluations ofe andf areindeterminately sequenced),F is also2 andfun is a binary invocable object.adjacent_transform_view always modelsforward_range, and modelsbidirectional_range,random_access_range, orsized_range, if adaptedview type models the corresponding concept.
Contents |
constructs aadjacent_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 the underlying (adapted) range satisfiessized_range(public member function)[edit] | |
(C++26) | returns the approximate size of the resultingapproximately_sized_range(public member function)[edit] |
Inherited fromstd::ranges::view_interface | |
returns whether the derived view is empty, provided only if it satisfiessized_range orforward_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 ifranges::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 satisfiesforward_range(public member function of std::ranges::view_interface<D>)[edit] | |
returns the last element in the derived view, provided only if it satisfiesbidirectional_range andcommon_range(public member function of std::ranges::view_interface<D>)[edit] | |
returns thenth element in the derived view, provided only if it satisfiesrandom_access_range(public member function of std::ranges::view_interface<D>)[edit] | |
| Type | Definition |
InnerView(private) | ranges::adjacent_view<V, N> (exposition-only member type*) |
inner_iterator(private) |
|
inner_sentinel(private) |
|
| Member | Description |
/*movable-box*/<F>fun_(private) | the transforming invocable object (exposition-only member object*) |
ranges::adjacent_view<V,N>inner_(private) | the stored view (exposition-only member object*) |
| the iterator type (exposition-only member class template*) | |
the sentinel type used whenadjacent_transform_view is not acommon_range(exposition-only member class template*) |
views::adjacent_transform only accepts foward ranges even whenN is0.
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_ranges_zip | 202110L | (C++23) | ranges::zip_view, ranges::zip_transform_view, ranges::adjacent_view, ranges::adjacent_transform_view |
#include <array>#include <iostream>#include <ranges> int main(){constexprstaticstd::array data{1,2,3,4,5,6};constexprint window{3}; auto Fun=[](auto...ints){return(...+ ints);};// Alternatively, the Fun could be any ternary (if window == 3) callable, e.g.:// auto Fun = [](int x, int y, int z) { return x + y + z; }; constexprauto view= data| std::views::adjacent_transform<window>(Fun); static_assert( view.size()==(data.size()- window+1)&&std::array{6,9,12,15}==std::array{view[0], view[1], view[2], view[3]}&& view[0]== Fun(data[0], data[1], data[2])&& view[1]== Fun(data[1], data[2], data[3])&& view[2]== Fun(data[2], data[3], data[4])&& view[3]== Fun(data[3], data[4], data[5])); for(int x: view)std::cout<< x<<' ';std::cout<<'\n';}
Output:
6 9 12 15
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 4098 | C++23 | views::adjacent_transform<0> used to accept input-only ranges | made rejected |
aview consisting of tuples of references to adjacent elements of the adapted view(class template)(range adaptor object)[edit] | |
aview of a sequence that applies a transformation function to each element(class template)(range adaptor object)[edit] | |
aview consisting of results of application of a transformation function to corresponding elements of the adapted views(class template)(customization point object)[edit] | |
(C++20) | applies a function to a range of elements (algorithm function object)[edit] |