tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
mismatch.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_MISMATCH_HPP
5#define TETL_ALGORITHM_MISMATCH_HPP
6
7#include <etl/_utility/pair.hpp>
8
9namespace etl {
10
11/// \brief Returns the first mismatching pair of elements from two ranges: one
12/// defined by `[first1, last1)` and another defined by [first2,last2). If last2
13/// is not provided (overloads (1-4)), it denotes first2 + (last1 - first1).
14/// Elements are compared using the given binary predicate pred.
15///
16/// \param first1 The first range of the elements.
17/// \param last1 The first range of the elements.
18/// \param first2 The second range of the elements.
19/// \param pred Binary predicate which returns ​true if the elements should be
20/// treated as equal.
21///
22/// https://en.cppreference.com/w/cpp/algorithm/mismatch
23///
24/// \ingroup algorithm
25template <typename InputIt1, typename InputIt2, typename Predicate>
26[[nodiscard]] constexpr auto mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, Predicate pred)
27 -> pair<InputIt1, InputIt2>
28{
29 for (; first1 != last1; ++first1, (void)++first2) {
30 if (not pred(*first1, *first2)) {
31 break;
32 }
33 }
34
35 return {first1, first2};
36}
37
38template <typename InputIt1, typename InputIt2>
39[[nodiscard]] constexpr auto mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2) -> pair<InputIt1, InputIt2>
40{
41 return etl::mismatch(first1, last1, first2, etl::equal_to());
42}
43
44template <typename InputIt1, typename InputIt2, typename Predicate>
45[[nodiscard]] constexpr auto mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Predicate pred)
46 -> pair<InputIt1, InputIt2>
47{
48 for (; first1 != last1 and first2 != last2; ++first1, (void)++first2) {
49 if (not pred(*first1, *first2)) {
50 break;
51 }
52 }
53
54 return {first1, first2};
55}
56
57template <typename InputIt1, typename InputIt2>
58[[nodiscard]] constexpr auto mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
59 -> pair<InputIt1, InputIt2>
60{
61 return etl::mismatch(first1, last1, first2, last2, etl::equal_to());
62}
63
64} // namespace etl
65
66#endif // TETL_ALGORITHM_MISMATCH_HPP
constexpr auto mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, Predicate pred) -> pair< InputIt1, InputIt2 >
Returns the first mismatching pair of elements from two ranges: one defined by [first1,...
Definition mismatch.hpp:26
Definition adjacent_find.hpp:9
constexpr auto mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2) -> pair< InputIt1, InputIt2 >
Definition mismatch.hpp:39
constexpr auto mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Predicate pred) -> pair< InputIt1, InputIt2 >
Definition mismatch.hpp:45
constexpr auto mismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) -> pair< InputIt1, InputIt2 >
Definition mismatch.hpp:58
etl::pair is a class template that provides a way to store two heterogeneous objects as a single unit...
Definition pair.hpp:37