tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
binary_search.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_BINARY_SEARCH_HPP
4#define TETL_ALGORITHM_BINARY_SEARCH_HPP
5
8
9namespace etl {
10
13
19template <typename ForwardIt, typename T, typename Compare>
20[[nodiscard]] constexpr auto binary_search(ForwardIt first, ForwardIt last, T const& value, Compare comp) -> bool
21{
22 first = etl::lower_bound(first, last, value, comp);
23 return first != last and not comp(value, *first);
24}
25
26template <typename ForwardIt, typename T>
27[[nodiscard]] constexpr auto binary_search(ForwardIt first, ForwardIt last, T const& value) -> bool
28{
29 return etl::binary_search(first, last, value, etl::less());
30}
31
33
34} // namespace etl
35
36#endif // TETL_ALGORITHM_BINARY_SEARCH_HPP
constexpr auto binary_search(ForwardIt first, ForwardIt last, T const &value, Compare comp) -> bool
Checks if an element equivalent to value appears within the range [first, last). For binary_search to...
Definition binary_search.hpp:20
constexpr auto lower_bound(ForwardIt first, ForwardIt last, T const &value, Compare comp) noexcept -> ForwardIt
Returns an iterator pointing to the first element in the range [first, last) that is not less than (i...
Definition lower_bound.hpp:21
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14