VCCC  2024.05
VisualCamp Common C++ library
contains.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_HPP_
6 #define VCCC_ALGORITHM_RANGES_CONTAINS_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_niebloid {
37  template<typename I, typename S, typename T, typename Proj = identity, std::enable_if_t<conjunction<
38  input_iterator<I>,
39  sentinel_for<S, I>,
40  projectable<I, Proj>,
41  indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*>
42  >::value, int> = 0>
43  constexpr bool operator()(I first, S last, const T& value, Proj proj = {}) const {
44  return ranges::find(std::move(first), last, value, proj) != last;
45  }
46 
47  template<typename R, typename T, typename Proj = identity, std::enable_if_t<conjunction<
48  input_range<R>,
49  projectable<iterator_t<R>, Proj>,
50  indirect_binary_predicate<ranges::equal_to, projected<iterator_t<R>, Proj>, const T*>
51  >::value, int> = 0>
52  constexpr bool operator()(R&& r, const T& value, Proj proj = {}) const {
53  return (*this)(ranges::begin(r), ranges::end(r), std::move(value), proj);
54  }
55 };
56 
57 } // namespace detail
58 
59 VCCC_INLINE_OR_STATIC constexpr detail::contains_niebloid contains{};
60 
62 
63 } // namespace ranges
64 } // namespace vccc
65 
66 #endif // VCCC_ALGORITHM_RANGES_CONTAINS_HPP_
constexpr VCCC_INLINE_OR_STATIC detail::find_niebloid find
Definition: find.hpp:54
constexpr VCCC_INLINE_OR_STATIC detail::contains_niebloid contains
Definition: contains.hpp:59
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< 0 > first
Definition: key_value.hpp:34
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35