is_heap.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_IS_HEAP_H
  9. #define _LIBCPP___ALGORITHM_IS_HEAP_H
  10. #include <__algorithm/comp.h>
  11. #include <__algorithm/comp_ref_type.h>
  12. #include <__algorithm/is_heap_until.h>
  13. #include <__config>
  14. #include <__iterator/iterator_traits.h>
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. # pragma GCC system_header
  17. #endif
  18. _LIBCPP_BEGIN_NAMESPACE_STD
  19. template <class _RandomAccessIterator, class _Compare>
  20. _LIBCPP_NODISCARD_EXT inline
  21. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  22. bool
  23. is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
  24. {
  25. return std::__is_heap_until(__first, __last, static_cast<__comp_ref_type<_Compare> >(__comp)) == __last;
  26. }
  27. template<class _RandomAccessIterator>
  28. _LIBCPP_NODISCARD_EXT inline
  29. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
  30. bool
  31. is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
  32. {
  33. return _VSTD::is_heap(__first, __last, __less<>());
  34. }
  35. _LIBCPP_END_NAMESPACE_STD
  36. #endif // _LIBCPP___ALGORITHM_IS_HEAP_H