Blender
V5.0
source
blender
blenlib
BLI_binary_search.hh
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2024 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#pragma once
6
10
11
#include <algorithm>
12
13
namespace
blender::binary_search
{
14
20
template
<
typename
Iterator,
typename
Predicate>
21
static
int64_t
first_if
(Iterator
begin
, Iterator end, Predicate &&predicate)
22
{
23
return
std::lower_bound(
begin
,
24
end,
25
nullptr
,
26
[&](
const
auto
&value,
void
*
/*dummy*/
) {
return
!predicate(value); }) -
27
begin
;
28
}
29
34
template
<
typename
Iterator,
typename
Predicate>
35
static
int64_t
last_if
(Iterator
begin
, Iterator end, Predicate &&predicate)
36
{
37
return
std::upper_bound(
begin
,
38
end,
39
nullptr
,
40
[&](
void
*
/*dummy*/
,
const
auto
&value) {
return
!predicate(value); }) -
41
begin
- 1;
42
}
43
44
template
<
typename
Range,
typename
Predicate>
45
int64_t
first_if
(
const
Range &range, Predicate &&predicate)
46
{
47
return
first_if
(range.begin(), range.end(), predicate);
48
}
49
50
template
<
typename
Range,
typename
Predicate>
51
int64_t
last_if
(
const
Range &range, Predicate &&predicate)
52
{
53
return
last_if
(range.begin(), range.end(), predicate);
54
}
55
56
}
// namespace blender::binary_search
begin
iter begin(iter)
int64_t
long long int int64_t
Definition
btConvexHullComputer.cpp:31
blender::binary_search
Definition
BLI_binary_search.hh:13
blender::binary_search::first_if
static int64_t first_if(Iterator begin, Iterator end, Predicate &&predicate)
Definition
BLI_binary_search.hh:21
blender::binary_search::last_if
static int64_t last_if(Iterator begin, Iterator end, Predicate &&predicate)
Definition
BLI_binary_search.hh:35
Generated on
for Blender by
doxygen
1.16.1