-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm.hpp
More file actions
54 lines (48 loc) · 1.54 KB
/
algorithm.hpp
File metadata and controls
54 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef ALGORITHM_HPP
#define ALGORITHM_HPP
#include "comp.hpp"
namespace ft
{
// equal
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
bool
equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, BinaryPredicate pred)
{
for (; first1 != last1; ++first1, (void) ++first2)
if (!pred(*first1, *first2))
return false;
return true;
}
template <class InputIterator1, class InputIterator2>
bool
equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
{
typedef typename ft::iterator_traits<InputIterator1>::value_type v1;
typedef typename ft::iterator_traits<InputIterator2>::value_type v2;
return ft::equal(first1, last1, first2, ft::__equal_to<v1, v2>());
}
template <class Compare, class InputIterator1, class InputIterator2>
bool
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, Compare comp)
{
for (; first2 != last2; ++first1, (void) ++first2)
{
if (first1 == last1 || comp(*first1, *first2))
return true;
if (comp(*first2, *first1))
return false;
}
return false;
}
template <class InputIterator1, class InputIterator2>
bool
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2)
{
return ft::lexicographical_compare(first1, last1, first2, last2,
__less<typename ft::iterator_traits<InputIterator1>::value_type,
typename ft::iterator_traits<InputIterator2>::value_type>());
}
};
#endif