Range-v3
Range algorithms, views, and actions for the Standard Library
ranges::views::transform_fn Struct Reference

#include <range/v3/view/transform.hpp>

+ Inheritance diagram for ranges::views::transform_fn:

Public Member Functions

template<typename Fun >
constexpr auto operator() (Fun fun) const
 
- Public Member Functions inherited from ranges::views::transform_base_fn
template<typename Rng , typename Fun >
requires transformable_range<Rng, Fun>
constexpr transform_view< all_t< Rng >, Fun > operator() (Rng &&rng, Fun fun) const
 
template<typename Rng1 , typename Rng2 , typename Fun >
requires transformable_ranges<Rng1, Rng2, Fun>
constexpr transform2_view< all_t< Rng1 >, all_t< Rng2 >, Fun > operator() (Rng1 &&rng1, Rng2 &&rng2, Fun fun) const
 

Related Functions

(Note that these are not member functions.)

constexpr transform_fn transform {}
 

Detailed Description

ranges::views::transform

The transform view takes in a function T -> U and converts an input range of T into an output range of U by calling the function on every element of the input range.

Example

#include <iostream>
#include <vector>
int main()
{
std::vector<int> numbers{1, 2, 3};
auto halved = numbers
// Divide each integer by 2, converting it into a double
| ranges::views::transform([](const int& num) {
return num / 2.0;
});
std::cout << halved << '\n';
}
_t< detail::transform_< Args... > > transform
Return a new meta::list constructed by transforming all the elements in L with the unary invocable Fn...
Definition: meta.hpp:1852

Output

[0.5,1,1.5]

Syntax

The input_range concept.
Definition: concepts.hpp:97
The output_range concept.
Definition: concepts.hpp:88

Parameters

transform_func
  • Maps an input value to an output value (transform_func(T) -> U)
input_range
  • The range of elements to transform
  • Reference type: T
output_range
  • The range of output values
  • Reference type: U
  • Value type: decay_t<U>
  • This range will have the same category as the input range (excluding contiguous ranges). Contiguous ranges are reduced to random access ranges.