tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
replace.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_HPP
5#define TETL_ALGORITHM_REPLACE_HPP
6
7#include <etl/_algorithm/replace_if.hpp>
8
9namespace etl {
10
11/// \brief Replaces all elements satisfying specific criteria with new_value in
12/// the range [first, last). Replaces all elements that are equal to
13/// old_value.
14/// \ingroup algorithm
15template <typename ForwardIt, typename T>
16constexpr auto replace(ForwardIt first, ForwardIt last, T const& oldValue, T const& newValue) -> void
17{
18 auto predicate = [&oldValue](auto const& item) { return item == oldValue; };
19 etl::replace_if(first, last, predicate, newValue);
20}
21
22} // namespace etl
23
24#endif // TETL_ALGORITHM_REPLACE_HPP
constexpr auto replace(ForwardIt first, ForwardIt last, T const &oldValue, T const &newValue) -> void
Replaces all elements satisfying specific criteria with new_value in the range [first,...
Definition replace.hpp:16
Definition adjacent_find.hpp:9