tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
includes.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_INCLUDES_HPP
5#define TETL_ALGORITHM_INCLUDES_HPP
6
7#include <etl/_functional/less.hpp>
8
9namespace etl {
10
11/// \brief Returns true if the sorted range `[first2, last2)` is a subsequence
12/// of the sorted range `[first1, last1)`. Both ranges must be sorted.
13/// \ingroup algorithm
14template <typename InputIt1, typename InputIt2, typename Compare>
15[[nodiscard]] constexpr auto includes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp)
16 -> bool
17{
18 for (; first2 != last2; ++first1) {
19 if (first1 == last1 or comp(*first2, *first1)) {
20 return false;
21 }
22 if (not comp(*first1, *first2)) {
23 ++first2;
24 }
25 }
26 return true;
27}
28
29/// \ingroup algorithm
30template <typename InputIt1, typename InputIt2>
31[[nodiscard]] constexpr auto includes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) -> bool
32{
33 return etl::includes(first1, last1, first2, last2, etl::less());
34}
35
36} // namespace etl
37
38#endif // TETL_ALGORITHM_INCLUDES_HPP
constexpr auto includes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp) -> bool
Returns true if the sorted range [first2, last2) is a subsequence of the sorted range [first1,...
Definition includes.hpp:15
constexpr auto includes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) -> bool
Definition includes.hpp:31
Definition adjacent_find.hpp:9
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15