mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-09 06:19:19 +00:00
Update kernel
This commit is contained in:
@ -53,14 +53,54 @@ namespace std
|
||||
}
|
||||
|
||||
template <class InputIt, class T>
|
||||
InputIt find(InputIt first, InputIt last, const T &value)
|
||||
constexpr InputIt find(InputIt first, InputIt last, const T &value)
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
if (*first == value)
|
||||
return first;
|
||||
++first;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
template <class InputIt, class UnaryPredicate>
|
||||
constexpr InputIt find_if(InputIt first, InputIt last, UnaryPredicate p)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
if (p(*first))
|
||||
return first;
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
template <class InputIt, class UnaryPredicate>
|
||||
constexpr InputIt find_if_not(InputIt first, InputIt last, UnaryPredicate q)
|
||||
{
|
||||
for (; first != last; ++first)
|
||||
if (!q(*first))
|
||||
return first;
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
template <class ForwardIt, class T>
|
||||
ForwardIt remove(ForwardIt first, ForwardIt last, const T &value)
|
||||
{
|
||||
first = std::find(first, last, value);
|
||||
if (first != last)
|
||||
for (ForwardIt i = first; ++i != last;)
|
||||
if (!(*i == value))
|
||||
*first++ = std::move(*i);
|
||||
return first;
|
||||
}
|
||||
|
||||
template <class ForwardIt, class UnaryPredicate>
|
||||
ForwardIt remove_if(ForwardIt first, ForwardIt last, UnaryPredicate p)
|
||||
{
|
||||
first = std::find_if(first, last, p);
|
||||
if (first != last)
|
||||
for (ForwardIt i = first; ++i != last;)
|
||||
if (!p(*i))
|
||||
*first++ = std::move(*i);
|
||||
return first;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user