ft_containers/containers/iterators/lexicographical_compare.hpp
2022-11-29 19:10:30 +01:00

41 lines
1.6 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexicographical_compare.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/28 14:58:42 by apommier #+# #+# */
/* Updated: 2022/11/29 17:28:55 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
namespace ft
{
template <class InputIterator1, class InputIterator2>
bool lexicographical_compare (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2) {
while (first1!=last1)
{
if (first2 == last2 || *first2 < *first1) return false;
else if (*first1 < *first2) return true;
++first1; ++first2;
}
return (first2 != last2);
}
template <class InputIterator1, class InputIterator2, class Compare>
bool lexicographical_compare (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp) {
while (first1 != last1)
{
if (comp(*first1, *first2))
return true;
if (comp(*first2, *first1))
return false;
++first1;
++first2;
}
return (first2 != last2);
}
}