tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
partition_copy.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_PARTITION_COPY_HPP
5#define TETL_ALGORITHM_PARTITION_COPY_HPP
6
7#include <etl/_utility/pair.hpp>
8
9namespace etl {
10
11/// \brief Copies the elements from the range `[first, last)` to two different
12/// ranges depending on the value returned by the predicate p. The elements that
13/// satisfy the predicate p are copied to the range beginning at
14/// destination_true. The rest of the elements are copied to the range beginning
15/// at destination_false.
16/// \details The behavior is undefined if the input range overlaps either of the
17/// output ranges.
18/// \ingroup algorithm
19template <typename InputIt, typename OutputIt1, typename OutputIt2, typename Predicate>
20constexpr auto
21partition_copy(InputIt first, InputIt last, OutputIt1 destinationTrue, OutputIt2 destinationFalse, Predicate p)
22 -> pair<OutputIt1, OutputIt2>
23{
24 for (; first != last; ++first) {
25 if (p(*first)) {
26 *destinationTrue = *first;
27 ++destinationTrue;
28 } else {
29 *destinationFalse = *first;
30 ++destinationFalse;
31 }
32 }
33
34 return {destinationTrue, destinationFalse};
35}
36
37} // namespace etl
38
39#endif // TETL_ALGORITHM_PARTITION_COPY_HPP
constexpr auto partition_copy(InputIt first, InputIt last, OutputIt1 destinationTrue, OutputIt2 destinationFalse, Predicate p) -> pair< OutputIt1, OutputIt2 >
Copies the elements from the range [first, last) to two different ranges depending on the value retur...
Definition partition_copy.hpp:21
Definition adjacent_find.hpp:9
etl::pair is a class template that provides a way to store two heterogeneous objects as a single unit...
Definition pair.hpp:37