Files
.github
.vscode
arch
core
exec
files
include
include_std
std
sys
algorithm
assert.h
atomic
cassert
cmath
cstddef
cstring
cxxabi.h
dlfcn.h
errno.h
exception
float.h
functional
limits.h
list
math.h
mutex
pthread.h
sched.h
std.hpp
stdarg.h
stdatomic.h
stddef.h
stdexcept
stdint.h
stdio.h
stdlib.h
string
string.h
strings.h
stropts.h
time.h
type_trails
typeinfo
unistd.h
unordered_map
unwind.h
utility
utsname.h
vector
wchar.h
kshell
library
network
profiling
storage
syscalls
tasking
tests
virtualization
.gdbinit
.gitignore
CREDITS.md
Doxyfile
ISSUES.md
LICENSE.md
LICENSES.md
Makefile
README.md
TODO.md
driver.h
dump.sh
kernel.cpp
kernel.h
kernel_config.cpp
kernel_thread.cpp
kernel_vfs.cpp
syscalls.h
Kernel/include_std/algorithm
2024-01-19 06:47:42 +02:00

107 lines
2.4 KiB
Plaintext

/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <utility>
namespace std
{
template <typename InputIt, typename OutputIt>
OutputIt copy(InputIt first, InputIt last, OutputIt result)
{
while (first != last)
{
*result = *first;
++result;
++first;
}
return result;
}
template <typename T>
void swap(T &a, T &b)
{
T temp = move(a);
a = move(b);
b = move(temp);
}
template <typename T>
constexpr const T &min(const T &a, const T &b)
{
return (a < b) ? a : b;
}
template <typename T>
constexpr const T &max(const T &a, const T &b)
{
return (a > b) ? a : b;
}
template <class InputIt, class T>
constexpr InputIt find(InputIt first, InputIt last, const T &value)
{
for (; first != last; ++first)
if (*first == value)
return 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;
}
}