lexicographical_compare.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
  9. #define _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H
  10. #include <__algorithm/comp.h>
  11. #include <__algorithm/comp_ref_type.h>
  12. #include <__config>
  13. #include <__iterator/iterator_traits.h>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. _LIBCPP_BEGIN_NAMESPACE_STD
  18. template <class _Compare, class _InputIterator1, class _InputIterator2>
  19. _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
  20. __lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
  21. _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
  22. {
  23. for (; __first2 != __last2; ++__first1, (void) ++__first2)
  24. {
  25. if (__first1 == __last1 || __comp(*__first1, *__first2))
  26. return true;
  27. if (__comp(*__first2, *__first1))
  28. return false;
  29. }
  30. return false;
  31. }
  32. template <class _InputIterator1, class _InputIterator2, class _Compare>
  33. _LIBCPP_NODISCARD_EXT inline
  34. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  35. bool
  36. lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
  37. _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
  38. {
  39. return _VSTD::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp);
  40. }
  41. template <class _InputIterator1, class _InputIterator2>
  42. _LIBCPP_NODISCARD_EXT inline
  43. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  44. bool
  45. lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
  46. _InputIterator2 __first2, _InputIterator2 __last2)
  47. {
  48. return _VSTD::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>());
  49. }
  50. _LIBCPP_END_NAMESPACE_STD
  51. #endif // _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H