tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
equal_range.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_EQUAL_RANGE_HPP
5#define TETL_ALGORITHM_EQUAL_RANGE_HPP
6
7#include <etl/_algorithm/lower_bound.hpp>
8#include <etl/_algorithm/upper_bound.hpp>
9#include <etl/_functional/less.hpp>
10#include <etl/_utility/pair.hpp>
11
12namespace etl {
13
14/// \brief Returns a range containing all elements equivalent to value in the
15/// range `[first, last)`.
16///
17/// https://en.cppreference.com/w/cpp/algorithm/equal_range
18///
19/// \ingroup algorithm
20template <typename ForwardIt, typename T, typename Compare>
21[[nodiscard]] constexpr auto equal_range(ForwardIt first, ForwardIt last, T const& value, Compare comp)
22 -> pair<ForwardIt, ForwardIt>
23{
24 return etl::make_pair(etl::lower_bound(first, last, value, comp), etl::upper_bound(first, last, value, comp));
25}
26
27/// \ingroup algorithm
28template <typename ForwardIt, typename T>
29[[nodiscard]] constexpr auto equal_range(ForwardIt first, ForwardIt last, T const& value) -> pair<ForwardIt, ForwardIt>
30{
31 return etl::equal_range(first, last, value, etl::less());
32}
33
34} // namespace etl
35
36#endif // TETL_ALGORITHM_EQUAL_RANGE_HPP
constexpr auto equal_range(ForwardIt first, ForwardIt last, T const &value, Compare comp) -> pair< ForwardIt, ForwardIt >
Returns a range containing all elements equivalent to value in the range [first, last).
Definition equal_range.hpp:21
constexpr auto equal_range(ForwardIt first, ForwardIt last, T const &value) -> pair< ForwardIt, ForwardIt >
Definition equal_range.hpp:29
Definition adjacent_find.hpp:9
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:15
etl::pair is a class template that provides a way to store two heterogeneous objects as a single unit...
Definition pair.hpp:37