tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
transform.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_TRANSFORM_HPP
5#define TETL_ALGORITHM_TRANSFORM_HPP
6
7namespace etl {
8
9/// \ingroup algorithm
10/// @{
11
12/// Applies the given function to a range and stores the result in
13/// another range, beginning at dest. The unary operation op is applied to
14/// the range defined by `[first, last)`.
15///
16/// https://en.cppreference.com/w/cpp/algorithm/transform
17///
18/// \param first The first range of elements to transform.
19/// \param last The first range of elements to transform.
20/// \param dest The beginning of the destination range, may be equal to first.
21/// \param op Unary operation function object that will be applied.
22///
23/// \ingroup algorithm
24template <typename InputIt, typename OutputIt, typename UnaryOp>
25constexpr auto transform(InputIt first, InputIt last, OutputIt dest, UnaryOp op) -> OutputIt
26{
27 for (; first != last; ++first, (void)++dest) {
28 *dest = op(*first);
29 }
30 return dest;
31}
32
33template <typename InputIt1, typename InputIt2, typename OutputIt, typename BinaryOp>
34constexpr auto transform(InputIt1 first1, InputIt1 last1, InputIt2 first2, OutputIt dest, BinaryOp op) -> OutputIt
35{
36 for (; first1 != last1; ++first1, (void)++first2, ++dest) {
37 *dest = op(*first1, *first2);
38 }
39 return dest;
40}
41
42/// @}
43
44} // namespace etl
45
46#endif // TETL_ALGORITHM_TRANSFORM_HPP
constexpr auto transform(InputIt first, InputIt last, OutputIt dest, UnaryOp op) -> OutputIt
Definition transform.hpp:25
constexpr auto transform(InputIt1 first1, InputIt1 last1, InputIt2 first2, OutputIt dest, BinaryOp op) -> OutputIt
Definition transform.hpp:34
Definition adjacent_find.hpp:9