tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
is_partitioned.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_IS_PARTITIONED_HPP
5#define TETL_ALGORITHM_IS_PARTITIONED_HPP
6
7namespace etl {
8
9/// \brief Returns true if all elements in the range `[first, last)` that
10/// satisfy the predicate p appear before all elements that don't. Also returns
11/// true if the range is empty.
12///
13/// https://en.cppreference.com/w/cpp/algorithm/is_partitioned
14///
15/// \ingroup algorithm
16template <typename InputIt, typename Predicate>
17[[nodiscard]] constexpr auto is_partitioned(InputIt first, InputIt last, Predicate p) -> bool
18{
19 for (; first != last; ++first) {
20 if (not p(*first)) {
21 break;
22 }
23 }
24
25 for (; first != last; ++first) {
26 if (p(*first)) {
27 return false;
28 }
29 }
30
31 return true;
32}
33
34} // namespace etl
35
36#endif // TETL_ALGORITHM_IS_PARTITIONED_HPP
constexpr auto is_partitioned(InputIt first, InputIt last, Predicate p) -> bool
Returns true if all elements in the range [first, last) that satisfy the predicate p appear before al...
Definition is_partitioned.hpp:17
Definition adjacent_find.hpp:9