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
7
namespace
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
19
template
<
typename
InIt,
typename
OutIt,
typename
Pred>
20
constexpr
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
etl::copy_if
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
etl
Definition
adjacent_find.hpp:9
include
etl
_algorithm
copy_if.hpp
Generated on Sun Sep 7 2025 19:14:46 for tetl by
1.9.8