mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
add forgotten file again
This commit is contained in:
parent
2fa24b5eae
commit
b01e20b4cb
1 changed files with 23 additions and 0 deletions
23
llarp/util/algorithm.hpp
Normal file
23
llarp/util/algorithm.hpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace llarp::util
|
||||
{
|
||||
/// remove items from a container if a predicate is true
|
||||
/// return the number of items removed
|
||||
constexpr auto erase_if = [](auto& container, auto&& pred) -> std::size_t {
|
||||
std::size_t removed = 0;
|
||||
for (auto itr = container.begin(); itr != container.end();)
|
||||
{
|
||||
if (pred(*itr))
|
||||
{
|
||||
itr = container.erase(itr);
|
||||
removed++;
|
||||
}
|
||||
else
|
||||
itr++;
|
||||
}
|
||||
return removed;
|
||||
};
|
||||
} // namespace llarp::util
|
Loading…
Reference in a new issue