|
Range primitives | |||||||
|
Range concepts | |||||||||||||||||||
|
Range factories | |||||||||
|
Range adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
Helper items | |||||||||||||||||
|
Defined in header <ranges> | ||
(1) | ||
template<ranges::input_range V, std::copy_constructible F> | (since C++20) (until C++23) | |
template<ranges::input_range V, std::move_constructible F> | (since C++23) | |
namespace views{ inlineconstexpr/*unspecified*/ transform=/*unspecified*/; | (2) | (since C++20) |
Call signature | ||
template<ranges::viewable_range R,class F> requires/* see below */ | (since C++20) | |
template<class F> constexpr/*range adaptor closure*/ transform( F&& fun); | (since C++20) | |
view
of an underlying sequence after applying a transformation function to each element.transform_view
models the conceptsrandom_access_range
,bidirectional_range
,forward_range
,input_range
,common_range
, andsized_range
when the underlying viewV
models respective concepts.
Contents |
Member | Description |
V base_ (private) | the underlying view (exposition-only member object*) |
copyable-box <F> (until C++23)movable-box <F> (since C++23)fun_ (private) | the underlying function object (exposition-only member object*) |
constructs atransform_view (public member function)[edit] | |
returns a copy of the underlying (adapted) 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 then th element in the derived view, provided only if it satisfiesrandom_access_range (public member function of std::ranges::view_interface<D> )[edit] |
the iterator type (exposition-only member class template*) | |
the sentinel type (exposition-only member class template*) |
#include <algorithm>#include <cstdio>#include <iterator>#include <ranges>#include <string> char rot13a(constchar x,constchar a){return a+(x- a+13)%26;} char rot13(constchar x){if('Z'>= x and x>='A')return rot13a(x,'A'); if('z'>= x and x>='a')return rot13a(x,'a'); return x;} int main(){auto show=[](constunsignedchar x){std::putchar(x);}; std::string in{"cppreference.com\n"}; std::ranges::for_each(in, show); std::ranges::for_each(in| std::views::transform(rot13), show); std::string out; std::ranges::copy(std::views::transform(in, rot13),std::back_inserter(out)); std::ranges::for_each(out, show); std::ranges::for_each(out| std::views::transform(rot13), show);}
Output:
cppreference.compccersrerapr.pbzpccersrerapr.pbzcppreference.com
(C++20) | applies a function to a range of elements (algorithm function object)[edit] |