Loading...
Searching...
No Matches
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 Symbols

(Note that these are not member symbols.)
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>
#include <range/v3/view/transform.hpp>
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';
}
transform.hpp

### Output

[0.5,1,1.5]

## Syntax

auto output_range = input_range | ranges::views::transform(transform_func);
ranges::input_range
The input_range concept.
Definition concepts.hpp:97
ranges::output_range
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.