lexicographical_compare.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 __lexicographical_compare(
  20. _InputIterator1 __first1,
  21. _InputIterator1 __last1,
  22. _InputIterator2 __first2,
  23. _InputIterator2 __last2,
  24. _Compare __comp) {
  25. for (; __first2 != __last2; ++__first1, (void)++__first2) {
  26. if (__first1 == __last1 || __comp(*__first1, *__first2))
  27. return true;
  28. if (__comp(*__first2, *__first1))
  29. return false;
  30. }
  31. return false;
  32. }
  33. template <class _InputIterator1, class _InputIterator2, class _Compare>
  34. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
  35. _InputIterator1 __first1,
  36. _InputIterator1 __last1,
  37. _InputIterator2 __first2,
  38. _InputIterator2 __last2,
  39. _Compare __comp) {
  40. return std::__lexicographical_compare<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __comp);
  41. }
  42. template <class _InputIterator1, class _InputIterator2>
  43. _LIBCPP_NODISCARD_EXT inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool lexicographical_compare(
  44. _InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) {
  45. return std::lexicographical_compare(__first1, __last1, __first2, __last2, __less<>());
  46. }
  47. _LIBCPP_END_NAMESPACE_STD
  48. #endif // _LIBCPP___ALGORITHM_LEXICOGRAPHICAL_COMPARE_H