VCCC  2024.05
VisualCamp Common C++ library
find_first_of.hpp
Go to the documentation of this file.
1 //
2 // Created by YongGyu Lee on 4/12/24.
3 //
4 
5 #ifndef VCCC_ALGORITHM_RANGES_FIND_FIRST_OF_HPP_
6 #define VCCC_ALGORITHM_RANGES_FIND_FIRST_OF_HPP_
7 
8 #include <type_traits>
9 #include <utility>
10 
18 #include "vccc/__ranges/begin.hpp"
20 #include "vccc/__ranges/end.hpp"
25 
26 namespace vccc {
27 namespace ranges {
28 namespace detail {
29 
30 struct find_first_of_niebloid {
31  template<typename I1, typename S1,
32  typename I2, typename S2,
33  typename Pred = ranges::equal_to,
34  typename Proj1 = identity,
35  typename Proj2 = identity,
36  std::enable_if_t<conjunction<
37  input_iterator<I1>, sentinel_for<S1, I1>,
38  forward_iterator<I2>, sentinel_for<S2, I2>,
39  indirectly_comparable<I1, I2, Pred, Proj1, Proj2>
40  >::value, int> = 0>
41  constexpr I1 operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) const {
42  for (; first1 != last1; ++first1) {
43  for (auto it = first2; it != last2; ++it) {
44  if (vccc::invoke(pred, vccc::invoke(proj1, *first1), vccc::invoke(proj2, *it))) {
45  return first1;
46  }
47  }
48  }
49 
50  return first1;
51  }
52 
53  template<typename R1, typename R2,
54  typename Pred = ranges::equal_to, typename Proj1 = identity, typename Proj2 = identity,
55  std::enable_if_t<conjunction<
56  input_range<R1>, forward_range<R2>,
57  indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Pred, Proj1, Proj2>
58  >::value, int> = 0>
59  constexpr borrowed_iterator_t<R1> operator()(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) const {
60  return (*this)(ranges::begin(r1), ranges::end(r1), ranges::begin(r2), ranges::end(r2), std::move(pred), std::move(proj1), std::move(proj2));
61  }
62 };
63 
64 } // namespace detail
65 
68 
69 VCCC_INLINE_OR_STATIC constexpr detail::find_first_of_niebloid find_first_of{};
70 
72 
73 } // namespace ranges
74 } // namespace vccc
75 
76 #endif // VCCC_ALGORITHM_RANGES_FIND_FIRST_OF_HPP_
constexpr VCCC_INLINE_OR_STATIC detail::find_first_of_niebloid find_first_of
Definition: find_first_of.hpp:69
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
#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