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