tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
replace_if.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_REPLACE_IF_HPP
5#define TETL_ALGORITHM_REPLACE_IF_HPP
6
7namespace etl {
8
9/// \brief Replaces all elements satisfying specific criteria with new_value in
10/// the range [first, last). Replaces all elements for which predicate p
11/// returns true.
12/// \ingroup algorithm
13template <typename ForwardIt, typename Predicate, typename T>
14constexpr auto replace_if(ForwardIt first, ForwardIt last, Predicate p, T const& newValue) -> void
15{
16 for (; first != last; ++first) {
17 if (p(*first)) {
18 *first = newValue;
19 }
20 }
21}
22
23} // namespace etl
24
25#endif // TETL_ALGORITHM_REPLACE_IF_HPP
constexpr auto replace_if(ForwardIt first, ForwardIt last, Predicate p, T const &newValue) -> void
Replaces all elements satisfying specific criteria with new_value in the range [first,...
Definition replace_if.hpp:14
Definition adjacent_find.hpp:9