Fix: Add missing header used by recent backport fix

This was added in main by 2cfcb8b0b8, and used by
6a05e5161b which was cherry-picked from main
to the release branch.
This commit is contained in:
Hans Goudey
2023-06-16 09:18:44 -04:00
parent 6a05e5161b
commit 05190a5a23
2 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/** \file
* \ingroup bli
*/
#include <algorithm>
#include "BLI_utildefines.h"
namespace blender::binary_search {
/**
* Find the index of the first element where the predicate is true. The predicate must also be
* true for all following elements. If the predicate is false for all elements, the size of the
* range is returned.
*/
template<typename Iterator, typename Predicate>
int64_t find_predicate_begin(Iterator begin, Iterator end, Predicate &&predicate)
{
return std::lower_bound(begin,
end,
nullptr,
[&](const auto &value, void * /*dummy*/) { return !predicate(value); }) -
begin;
}
template<typename Range, typename Predicate>
int64_t find_predicate_begin(const Range &range, Predicate &&predicate)
{
return find_predicate_begin(range.begin(), range.end(), predicate);
}
} // namespace blender::binary_search

View File

@@ -182,6 +182,7 @@ set(SRC
BLI_assert.h
BLI_astar.h
BLI_atomic_disjoint_set.hh
BLI_binary_search.hh
BLI_bit_group_vector.hh
BLI_bit_ref.hh
BLI_bit_span.hh