Path: blob/main/contrib/llvm-project/libcxx/include/__algorithm/binary_search.h
35232 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef _LIBCPP___ALGORITHM_BINARY_SEARCH_H9#define _LIBCPP___ALGORITHM_BINARY_SEARCH_H1011#include <__algorithm/comp.h>12#include <__algorithm/comp_ref_type.h>13#include <__algorithm/lower_bound.h>14#include <__config>15#include <__iterator/iterator_traits.h>1617#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)18# pragma GCC system_header19#endif2021_LIBCPP_BEGIN_NAMESPACE_STD2223template <class _ForwardIterator, class _Tp, class _Compare>24_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool25binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value, _Compare __comp) {26__first = std::lower_bound<_ForwardIterator, _Tp, __comp_ref_type<_Compare> >(__first, __last, __value, __comp);27return __first != __last && !__comp(__value, *__first);28}2930template <class _ForwardIterator, class _Tp>31_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool32binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {33return std::binary_search(__first, __last, __value, __less<>());34}3536_LIBCPP_END_NAMESPACE_STD3738#endif // _LIBCPP___ALGORITHM_BINARY_SEARCH_H394041