tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
copy_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_COPY_IF_HPP
5#define TETL_ALGORITHM_COPY_IF_HPP
6
7namespace etl {
8
9/// Copies the elements in the range, defined by `[first, last)`, to
10/// another range beginning at destination.
11///
12/// Only copies the elements for which the predicate pred returns true.
13/// The relative order of the elements that are copied is preserved. The
14/// behavior is undefined if the source and the destination ranges overlap.
15///
16/// \returns Output iterator to the element in the destination range, one past
17/// the last element copied.
18/// \ingroup algorithm
19template <typename InIt, typename OutIt, typename Pred>
20constexpr auto copy_if(InIt first, InIt last, OutIt dFirst, Pred pred) -> OutIt
21{
22 while (first != last) {
23 if (pred(*first)) {
24 *dFirst++ = *first;
25 }
26 ++first;
27 }
28 return dFirst;
29}
30
31} // namespace etl
32
33#endif // TETL_ALGORITHM_COPY_IF_HPP
constexpr auto copy_if(InIt first, InIt last, OutIt dFirst, Pred pred) -> OutIt
Copies the elements in the range, defined by [first, last), to another range beginning at destination...
Definition copy_if.hpp:20
Definition adjacent_find.hpp:9