22 #ifndef ABSL_ALGORITHM_ALGORITHM_H_ 23 #define ABSL_ALGORITHM_ALGORITHM_H_ 27 #include <type_traits> 31 namespace algorithm_internal {
35 template <
typename T,
typename U>
41 template <
typename InputIter1,
typename InputIter2,
typename Pred>
42 bool EqualImpl(InputIter1 first1, InputIter1 last1, InputIter2 first2,
43 InputIter2 last2, Pred pred, std::input_iterator_tag,
44 std::input_iterator_tag) {
46 if (first1 == last1)
return first2 == last2;
47 if (first2 == last2)
return false;
48 if (!pred(*first1, *first2))
return false;
54 template <
typename InputIter1,
typename InputIter2,
typename Pred>
55 bool EqualImpl(InputIter1 first1, InputIter1 last1, InputIter2 first2,
56 InputIter2 last2, Pred&& pred, std::random_access_iterator_tag,
57 std::random_access_iterator_tag) {
58 return (last1 - first1 == last2 - first2) &&
59 std::equal(first1, last1, first2, std::forward<Pred>(pred));
65 template <
typename InputIter1,
typename InputIter2>
66 bool EqualImpl(InputIter1 first1, InputIter1 last1, InputIter2 first2,
68 std::random_access_iterator_tag,
69 std::random_access_iterator_tag) {
70 return (last1 - first1 == last2 - first2) &&
71 std::equal(first1, last1, first2);
74 template <
typename It>
75 It
RotateImpl(It first, It middle, It last, std::true_type) {
79 template <
typename It>
80 It
RotateImpl(It first, It middle, It last, std::false_type) {
82 return std::next(first, std::distance(middle, last));
98 template <
typename InputIter1,
typename InputIter2,
typename Pred>
99 bool equal(InputIter1 first1, InputIter1 last1, InputIter2 first2,
100 InputIter2 last2, Pred&& pred) {
102 first1, last1, first2, last2, std::forward<Pred>(pred),
103 typename std::iterator_traits<InputIter1>::iterator_category{},
104 typename std::iterator_traits<InputIter2>::iterator_category{});
109 template <
typename InputIter1,
typename InputIter2>
110 bool equal(InputIter1 first1, InputIter1 last1, InputIter2 first2,
123 template <
typename InputIterator,
typename EqualityComparable>
125 const EqualityComparable&
value) {
126 return std::find(first, last, value) != last;
139 template <
typename ForwardIterator>
140 ForwardIterator
rotate(ForwardIterator first, ForwardIterator middle,
141 ForwardIterator last) {
144 std::is_same<decltype(
std::rotate(first, middle, last)),
150 #endif // ABSL_ALGORITHM_ALGORITHM_H_ It RotateImpl(It first, It middle, It last, std::true_type)
AllocList * next[kMaxLevel]
bool linear_search(InputIterator first, InputIterator last, const EqualityComparable &value)
bool equal(InputIter1 first1, InputIter1 last1, InputIter2 first2, InputIter2 last2, Pred &&pred)
bool EqualImpl(InputIter1 first1, InputIter1 last1, InputIter2 first2, InputIter2 last2, Pred pred, std::input_iterator_tag, std::input_iterator_tag)
ForwardIterator rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last)
bool operator()(const T &a, const U &b) const