VCCC  2024.05
VisualCamp Common C++ library
find.hpp
Go to the documentation of this file.
1 //
2 // Created by yonggyulee on 1/18/24.
3 //
4 
5 #ifndef VCCC_ALGORITHM_RANGES_FIND_HPP
6 #define VCCC_ALGORITHM_RANGES_FIND_HPP
7 
8 #include <functional>
9 #include <type_traits>
10 
17 #include "vccc/__ranges/begin.hpp"
19 #include "vccc/__ranges/end.hpp"
21 
22 namespace vccc {
23 namespace ranges {
24 namespace detail {
25 
26 struct find_niebloid {
27  template<typename I, typename S, typename T, typename Proj = identity, std::enable_if_t<
28  algo_check_binary_input_iterator<indirect_binary_predicate, I, S, const T*, Proj, ranges::equal_to>
29  ::value, int> = 0>
30  constexpr I operator()(I first, S last, const T& value, Proj proj = {}) const {
31  using namespace vccc::rel_ops;
32  for (; first != last; ++first) {
33  if (vccc::invoke(proj, *first) == value) {
34  return first;
35  }
36  }
37  return first;
38  }
39 
40  template<typename R, typename T, typename Proj = identity, std::enable_if_t<
41  algo_check_binary_input_range<indirect_binary_predicate, R, const T*, Proj, ranges::equal_to>
42  ::value, int> = 0>
43  constexpr borrowed_iterator_t<R>
44  operator()(R&& r, const T& value, Proj proj = {}) const {
45  return (*this)(ranges::begin(r), ranges::end(r), value, std::ref(proj));
46  }
47 };
48 
49 } // namespace detail
50 
53 
54 VCCC_INLINE_OR_STATIC constexpr detail::find_niebloid find{};
55 
57 
58 } // namespace ranges
59 } // namespace vccc
60 
61 #endif // VCCC_ALGORITHM_RANGES_FIND_HPP
constexpr VCCC_INLINE_OR_STATIC detail::find_niebloid find
Definition: find.hpp:54
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: cxx20_rel_ops.hpp:17
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 0 > first
Definition: key_value.hpp:34
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35