VCCC  2024.05
VisualCamp Common C++ library
mismatch.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 1/26/24.
3 //
4 
5 #ifndef VCCC_ALGORITHM_RANGES_MISMATCH_HPP
6 #define VCCC_ALGORITHM_RANGES_MISMATCH_HPP
7 
8 #include <type_traits>
9 #include <functional>
10 
19 #include "vccc/__ranges/begin.hpp"
21 #include "vccc/__ranges/end.hpp"
25 
26 namespace vccc {
27 namespace ranges {
28 
31 
32 template<typename I1, typename I2>
34 
35 namespace detail {
36 
37 struct mismatch_niebloid {
38  template<
39  typename I1, typename S1,
40  typename I2, typename S2,
41  typename Pred = equal_to,
42  typename Proj1 = identity, typename Proj2 = identity,
43  std::enable_if_t<conjunction<
47  >::value, int> = 0
48  >
49  constexpr mismatch_result<I1, I2>
50  operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) const {
51  for (; first1 != last1 && first2 != last2; ++first1, (void)++first2) {
52  if (!vccc::invoke(pred, vccc::invoke(proj1, *first1), vccc::invoke(proj2, *first2))) {
53  break;
54  }
55  }
56  return {first1, first2};
57  }
58 
59  template<typename R1, typename R2, typename Pred = equal_to, typename Proj1 = identity, typename Proj2 = identity>
61  operator()(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) const {
62  return (*this)(
64  std::ref(pred), std::ref(proj1), std::ref(proj2));
65  }
66 };
67 
68 } // namespace detail
69 
70 VCCC_INLINE_OR_STATIC constexpr detail::mismatch_niebloid mismatch{};
71 
73 
74 } // namespace ranges
75 } // namespace vccc
76 
77 #endif // VCCC_ALGORITHM_RANGES_MISMATCH_HPP
constexpr VCCC_INLINE_OR_STATIC detail::mismatch_niebloid mismatch
Definition: mismatch.hpp:70
constexpr invoke_result_t< F, Args... > invoke(F &&f, Args &&... args) noexcept(is_nothrow_invocable< F, Args... >::value)
Definition: invoke.hpp:38
constexpr VCCC_INLINE_OR_STATIC detail::begin_niebloid begin
returns an iterator to the beginning of a range
Definition: begin.hpp:116
constexpr VCCC_INLINE_OR_STATIC detail::end_niebloid end
returns a sentinel indicating the end of a range
Definition: end.hpp:120
typename borrowed_iterator< R >::type borrowed_iterator_t
Definition: borrowed_iterator_t.hpp:36
#define VCCC_INLINE_OR_STATIC
Definition: inline_or_static.hpp:9
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
Definition: conjunction.hpp:22
function object that returns its argument unchanged
Definition: identity.hpp:25
specifies that the values referenced by two indirectly_readable types can be compared
Definition: indirectly_comparable.hpp:49
specifies that a type is an input iterator, that is, its referenced values can be read and it can be ...
Definition: input_iterator.hpp:55
Definition: equal_to.hpp:20
Definition: in_in_result.hpp:22
Definition: sentinel_for.hpp:24