diff --git a/include_std/algorithm b/include_std/algorithm index f717ae8a..d55c8764 100644 --- a/include_std/algorithm +++ b/include_std/algorithm @@ -32,6 +32,16 @@ namespace std return result; } + template + BidirIt2 copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 d_last) + { + while (first != last) + { + *(--d_last) = *(--last); + } + return d_last; + } + template void swap(T &a, T &b) { @@ -65,6 +75,26 @@ namespace std : v; } + template + ForwardIt1 search(ForwardIt1 first, ForwardIt1 last, + ForwardIt2 s_first, ForwardIt2 s_last) + { + for (; first != last; ++first) + { + ForwardIt1 it = first; + for (ForwardIt2 s_it = s_first;; ++it, ++s_it) + { + if (s_it == s_last) + return first; + if (it == last) + return last; + if (!(*it == *s_it)) + break; + } + } + return last; + } + template constexpr InputIt find(InputIt first, InputIt last, const T &value) { @@ -95,6 +125,35 @@ namespace std return last; } + template + ForwardIt1 find_end(ForwardIt1 first, ForwardIt1 last, + ForwardIt2 s_first, ForwardIt2 s_last) + { + if (s_first == s_last) + return last; + ForwardIt1 result = last; + while (true) + { + ForwardIt1 new_result = std::search(first, last, s_first, s_last); + if (new_result == last) + return result; + result = new_result; + first = new_result; + ++first; + } + } + + template + InputIt find_first_of(InputIt first, InputIt last, + ForwardIt s_first, ForwardIt s_last) + { + for (; first != last; ++first) + for (ForwardIt it = s_first; it != s_last; ++it) + if (*first == *it) + return first; + return last; + } + template ForwardIt remove(ForwardIt first, ForwardIt last, const T &value) { @@ -123,4 +182,15 @@ namespace std for (; first != last; ++first) *first = value; } + + template + OutputIt fill_n(OutputIt first, Size count, const T &value) + { + for (Size i = 0; i < count; ++i) + { + *first = value; + ++first; + } + return first; + } } diff --git a/include_std/cfloat b/include_std/cfloat new file mode 100644 index 00000000..57a26015 --- /dev/null +++ b/include_std/cfloat @@ -0,0 +1,75 @@ +/* + 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 . +*/ + +#pragma once + +#define INFINITY (__builtin_inff()) +#define NAN (__builtin_nanf("")) +#define FLT_ROUNDS 1 +#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ + +#define FLT_HAS_SUBNORM __FLT_HAS_DENORM__ +#define DBL_HAS_SUBNORM __DBL_HAS_DENORM__ +#define LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__ + +#define FLT_RADIX __FLT_RADIX__ + +#define FLT_MANT_DIG __FLT_MANT_DIG__ +#define DBL_MANT_DIG __DBL_MANT_DIG__ +#define LDBL_MANT_DIG __LDBL_MANT_DIG__ + +#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__ +#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__ +#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__ + +#define DECIMAL_DIG __DECIMAL_DIG__ + +#define FLT_DIG __FLT_DIG__ +#define DBL_DIG __DBL_DIG__ +#define LDBL_DIG __LDBL_DIG__ + +#define FLT_MIN_EXP __FLT_MIN_EXP__ +#define DBL_MIN_EXP __DBL_MIN_EXP__ +#define LDBL_MIN_EXP __LDBL_MIN_EXP__ + +#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__ +#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__ +#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ + +#define FLT_MAX_EXP __FLT_MAX_EXP__ +#define DBL_MAX_EXP __DBL_MAX_EXP__ +#define LDBL_MAX_EXP __LDBL_MAX_EXP__ + +#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__ +#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__ +#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ + +#define FLT_MAX __FLT_MAX__ +#define DBL_MAX __DBL_MAX__ +#define LDBL_MAX __LDBL_MAX__ + +#define FLT_EPSILON __FLT_EPSILON__ +#define DBL_EPSILON __DBL_EPSILON__ +#define LDBL_EPSILON __LDBL_EPSILON__ + +#define FLT_MIN __FLT_MIN__ +#define DBL_MIN __DBL_MIN__ +#define LDBL_MIN __LDBL_MIN__ + +#define FLT_TRUE_MIN __FLT_DENORM_MIN__ +#define DBL_TRUE_MIN __DBL_DENORM_MIN__ +#define LDBL_TRUE_MIN __LDBL_DENORM_MIN__ diff --git a/include_std/climits b/include_std/climits new file mode 100644 index 00000000..8e79e646 --- /dev/null +++ b/include_std/climits @@ -0,0 +1,56 @@ +/* + 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 . +*/ + +#undef CHAR_BIT +#undef SCHAR_MIN +#undef SCHAR_MAX +#undef UCHAR_MAX +#undef CHAR_MIN +#undef CHAR_MAX +#undef MB_LEN_MAX +#undef SHRT_MIN +#undef SHRT_MAX +#undef USHRT_MAX +#undef INT_MIN +#undef INT_MAX +#undef UINT_MAX +#undef LONG_MIN +#undef LONG_MAX +#undef ULONG_MAX +#undef LLONG_MIN +#undef LLONG_MAX +#undef ULLONG_MAX + +#define CHAR_BIT __CHAR_BIT__ +#define SCHAR_MIN (-SCHAR_MAX - 1) +#define SCHAR_MAX __SCHAR_MAX__ +#define UCHAR_MAX (SCHAR_MAX * 2 + 1) +#define CHAR_MIN 0 +#define CHAR_MAX SCHAR_MAX +#define MB_LEN_MAX 1 +#define SHRT_MIN (-SHRT_MAX - 1) +#define SHRT_MAX __SHRT_MAX__ +#define USHRT_MAX (SHRT_MAX * 2 + 1) +#define INT_MIN (-INT_MAX - 1) +#define INT_MAX __INT_MAX__ +#define UINT_MAX (INT_MAX * 2U + 1U) +#define LONG_MIN (-LONG_MAX - 1L) +#define LONG_MAX __LONG_MAX__ +#define ULONG_MAX (LONG_MAX * 2UL + 1UL) +#define LLONG_MIN (-LLONG_MAX - 1LL) +#define LLONG_MAX __LONG_LONG_MAX__ +#define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) diff --git a/include_std/cstddef b/include_std/cstddef index d0fe871a..6e18f8a9 100644 --- a/include_std/cstddef +++ b/include_std/cstddef @@ -19,6 +19,9 @@ namespace std { - typedef __SIZE_TYPE__ size_t; - typedef __PTRDIFF_TYPE__ ptrdiff_t; + typedef __SIZE_TYPE__ size_t; + typedef __PTRDIFF_TYPE__ ptrdiff_t; + using nullptr_t = decltype(nullptr); } + +static_assert(sizeof(std::nullptr_t) == sizeof(void *)); diff --git a/include_std/iterator b/include_std/iterator new file mode 100644 index 00000000..7089812d --- /dev/null +++ b/include_std/iterator @@ -0,0 +1,85 @@ +/* + 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 . +*/ + +#pragma once + +namespace std +{ + struct input_iterator_tag + { + }; + + struct output_iterator_tag + { + }; + + struct forward_iterator_tag : public input_iterator_tag + { + }; + + struct bidirectional_iterator_tag : public forward_iterator_tag + { + }; + + struct random_access_iterator_tag : public bidirectional_iterator_tag + { + }; + + struct contiguous_iterator_tag : public random_access_iterator_tag + { + }; + + template + class reverse_iterator + { + public: + /* FIXME: missing implementation */ + }; + + template + struct iterator_traits + { + public: + typedef Iter::difference_type difference_type; + + /* FIXME: missing implementation */ + }; + + template + constexpr typename std::iterator_traits::difference_type __do_distance(It first, It last, std::input_iterator_tag) + { + typename std::iterator_traits::difference_type result = 0; + while (first != last) + { + ++first; + ++result; + } + return result; + } + + template + constexpr typename std::iterator_traits::difference_type __do_distance(It first, It last, std::random_access_iterator_tag) + { + return last - first; + } + + template + constexpr typename std::iterator_traits::difference_type distance(InputIt first, InputIt last) + { + return __do_distance(first, last, typename std::iterator_traits::iterator_category()); + } +} diff --git a/include_std/limits b/include_std/limits new file mode 100644 index 00000000..bb967f4a --- /dev/null +++ b/include_std/limits @@ -0,0 +1,940 @@ +/* + 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 . +*/ + +#pragma once + +#include +#include + +namespace std +{ + enum float_round_style + { + round_indeterminate = -1, + round_toward_zero = 0, + round_to_nearest = 1, + round_toward_infinity = 2, + round_toward_neg_infinity = 3, + }; + + enum float_denorm_style + { + denorm_indeterminate = -1, + denorm_absent = 0, + denorm_present = 1 + }; + + template + class numeric_limits + { + public: + static constexpr bool is_specialized = false; + + static constexpr T min() { return T(); } + static constexpr T max() { return T(); } + static constexpr T lowest() { return T(); } + + static constexpr int digits = 0; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = 0; + static constexpr T epsilon() { return T(); } + static constexpr T round_error() { return T(); } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr T infinity() { return T(); } + static constexpr T quiet_NaN() { return T(); } + static constexpr T signaling_NaN() { return T(); } + static constexpr T denorm_min() { return T(); } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = false; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr bool min() { return false; } + static constexpr bool max() { return true; } + static constexpr bool lowest() { return false; } + + static constexpr int digits = 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr bool epsilon() { return 0; } + static constexpr bool round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr bool infinity() { return 0; } + static constexpr bool quiet_NaN() { return 0; } + static constexpr bool signaling_NaN() { return 0; } + static constexpr bool denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr char min() { return CHAR_MIN; } + static constexpr char max() { return CHAR_MAX; } + static constexpr char lowest() { return CHAR_MIN; } + + static constexpr int digits = CHAR_BIT; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = CHAR_MIN < 0; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr char epsilon() { return 0; } + static constexpr char round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr char infinity() { return 0; } + static constexpr char quiet_NaN() { return 0; } + static constexpr char signaling_NaN() { return 0; } + static constexpr char denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr signed char min() { return SCHAR_MIN; } + static constexpr signed char max() { return SCHAR_MAX; } + static constexpr signed char lowest() { return SCHAR_MIN; } + + static constexpr int digits = CHAR_BIT - 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = true; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr signed char epsilon() { return 0; } + static constexpr signed char round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr signed char infinity() { return 0; } + static constexpr signed char quiet_NaN() { return 0; } + static constexpr signed char signaling_NaN() { return 0; } + static constexpr signed char denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr unsigned char min() { return 0; } + static constexpr unsigned char max() { return UCHAR_MAX; } + static constexpr unsigned char lowest() { return 0; } + + static constexpr int digits = CHAR_BIT; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr unsigned char epsilon() { return 0; } + static constexpr unsigned char round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr unsigned char infinity() { return 0; } + static constexpr unsigned char quiet_NaN() { return 0; } + static constexpr unsigned char signaling_NaN() { return 0; } + static constexpr unsigned char denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr wchar_t min() { return __WCHAR_MIN__; } + static constexpr wchar_t max() { return __WCHAR_MAX__; } + static constexpr wchar_t lowest() { return __WCHAR_MIN__; } + + static constexpr int digits = CHAR_BIT * sizeof(wchar_t) - 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = __WCHAR_MIN__ < 0; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr wchar_t epsilon() { return 0; } + static constexpr wchar_t round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr wchar_t infinity() { return 0; } + static constexpr wchar_t quiet_NaN() { return 0; } + static constexpr wchar_t signaling_NaN() { return 0; } + static constexpr wchar_t denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr char8_t min() { return 0; } + static constexpr char8_t max() { return UCHAR_MAX; } + static constexpr char8_t lowest() { return 0; } + + static constexpr int digits = CHAR_BIT; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr char8_t epsilon() { return 0; } + static constexpr char8_t round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr char8_t infinity() { return 0; } + static constexpr char8_t quiet_NaN() { return 0; } + static constexpr char8_t signaling_NaN() { return 0; } + static constexpr char8_t denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr char16_t min() { return 0; } + static constexpr char16_t max() { return USHRT_MAX; } + static constexpr char16_t lowest() { return 0; } + + static constexpr int digits = CHAR_BIT * sizeof(char16_t) - 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr char16_t epsilon() { return 0; } + static constexpr char16_t round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr char16_t infinity() { return 0; } + static constexpr char16_t quiet_NaN() { return 0; } + static constexpr char16_t signaling_NaN() { return 0; } + static constexpr char16_t denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr char32_t min() { return 0; } + static constexpr char32_t max() { return UINT_MAX; } + static constexpr char32_t lowest() { return 0; } + + static constexpr int digits = CHAR_BIT * sizeof(char32_t) - 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr char32_t epsilon() { return 0; } + static constexpr char32_t round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr char32_t infinity() { return 0; } + static constexpr char32_t quiet_NaN() { return 0; } + static constexpr char32_t signaling_NaN() { return 0; } + static constexpr char32_t denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr short min() { return SHRT_MIN; } + static constexpr short max() { return SHRT_MAX; } + static constexpr short lowest() { return SHRT_MIN; } + + static constexpr int digits = CHAR_BIT * sizeof(short) - 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = true; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr short epsilon() { return 0; } + static constexpr short round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr short infinity() { return 0; } + static constexpr short quiet_NaN() { return 0; } + static constexpr short signaling_NaN() { return 0; } + static constexpr short denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr unsigned short min() { return 0; } + static constexpr unsigned short max() { return USHRT_MAX; } + static constexpr unsigned short lowest() { return 0; } + + static constexpr int digits = CHAR_BIT * sizeof(unsigned short); + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr unsigned short epsilon() { return 0; } + static constexpr unsigned short round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr unsigned short infinity() { return 0; } + static constexpr unsigned short quiet_NaN() { return 0; } + static constexpr unsigned short signaling_NaN() { return 0; } + static constexpr unsigned short denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr int min() { return INT_MIN; } + static constexpr int max() { return INT_MAX; } + static constexpr int lowest() { return INT_MIN; } + + static constexpr int digits = CHAR_BIT * sizeof(int) - 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = true; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr int epsilon() { return 0; } + static constexpr int round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr int infinity() { return 0; } + static constexpr int quiet_NaN() { return 0; } + static constexpr int signaling_NaN() { return 0; } + static constexpr int denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr unsigned int min() { return 0; } + static constexpr unsigned int max() { return UINT_MAX; } + static constexpr unsigned int lowest() { return 0; } + + static constexpr int digits = CHAR_BIT * sizeof(unsigned int); + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr unsigned int epsilon() { return 0; } + static constexpr unsigned int round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr unsigned int infinity() { return 0; } + static constexpr unsigned int quiet_NaN() { return 0; } + static constexpr unsigned int signaling_NaN() { return 0; } + static constexpr unsigned int denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr long min() { return LONG_MIN; } + static constexpr long max() { return LONG_MAX; } + static constexpr long lowest() { return LONG_MIN; } + + static constexpr int digits = CHAR_BIT * sizeof(long) - 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = true; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr long epsilon() { return 0; } + static constexpr long round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr long infinity() { return 0; } + static constexpr long quiet_NaN() { return 0; } + static constexpr long signaling_NaN() { return 0; } + static constexpr long denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr unsigned long min() { return 0; } + static constexpr unsigned long max() { return ULONG_MAX; } + static constexpr unsigned long lowest() { return 0; } + + static constexpr int digits = CHAR_BIT * sizeof(unsigned long); + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr unsigned long epsilon() { return 0; } + static constexpr unsigned long round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr unsigned long infinity() { return 0; } + static constexpr unsigned long quiet_NaN() { return 0; } + static constexpr unsigned long signaling_NaN() { return 0; } + static constexpr unsigned long denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr long long min() { return LLONG_MIN; } + static constexpr long long max() { return LLONG_MAX; } + static constexpr long long lowest() { return LLONG_MIN; } + + static constexpr int digits = CHAR_BIT * sizeof(long long) - 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = true; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr long long epsilon() { return 0; } + static constexpr long long round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr long long infinity() { return 0; } + static constexpr long long quiet_NaN() { return 0; } + static constexpr long long signaling_NaN() { return 0; } + static constexpr long long denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr unsigned long long min() { return 0; } + static constexpr unsigned long long max() { return ULLONG_MAX; } + static constexpr unsigned long long lowest() { return 0; } + + static constexpr int digits = CHAR_BIT * sizeof(unsigned long long); + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + static constexpr bool is_signed = false; + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + static constexpr unsigned long long epsilon() { return 0; } + static constexpr unsigned long long round_error() { return 0; } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + static constexpr unsigned long long infinity() { return 0; } + static constexpr unsigned long long quiet_NaN() { return 0; } + static constexpr unsigned long long signaling_NaN() { return 0; } + static constexpr unsigned long long denorm_min() { return 0; } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = true; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr float min() { return FLT_MIN; } + static constexpr float max() { return FLT_MAX; } + static constexpr float lowest() { return -FLT_MAX; } + + static constexpr int digits = FLT_MANT_DIG; + static constexpr int digits10 = FLT_DIG; + static constexpr int max_digits10 = FLT_DECIMAL_DIG; + + static constexpr bool is_signed = true; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = FLT_RADIX; + static constexpr float epsilon() { return FLT_EPSILON; } + static constexpr float round_error() { return 0.5f; } + + static constexpr int min_exponent = FLT_MIN_EXP; + static constexpr int min_exponent10 = FLT_MIN_10_EXP; + static constexpr int max_exponent = FLT_MAX_EXP; + static constexpr int max_exponent10 = FLT_MAX_10_EXP; + + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_present; + static constexpr bool has_denorm_loss = true; + static constexpr float infinity() { return INFINITY; } + static constexpr float quiet_NaN() { return NAN; } + static constexpr float signaling_NaN() { return NAN; } + static constexpr float denorm_min() { return FLT_TRUE_MIN; } + + static constexpr bool is_iec559 = true; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = true; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr double min() { return DBL_MIN; } + static constexpr double max() { return DBL_MAX; } + static constexpr double lowest() { return -DBL_MAX; } + + static constexpr int digits = DBL_MANT_DIG; + static constexpr int digits10 = DBL_DIG; + static constexpr int max_digits10 = DBL_DECIMAL_DIG; + + static constexpr bool is_signed = true; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = FLT_RADIX; + static constexpr double epsilon() { return DBL_EPSILON; } + static constexpr double round_error() { return 0.5; } + + static constexpr int min_exponent = DBL_MIN_EXP; + static constexpr int min_exponent10 = DBL_MIN_10_EXP; + static constexpr int max_exponent = DBL_MAX_EXP; + static constexpr int max_exponent10 = DBL_MAX_10_EXP; + + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_present; + static constexpr bool has_denorm_loss = true; + static constexpr double infinity() { return INFINITY; } + static constexpr double quiet_NaN() { return NAN; } + static constexpr double signaling_NaN() { return NAN; } + static constexpr double denorm_min() { return DBL_TRUE_MIN; } + + static constexpr bool is_iec559 = true; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = true; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; + }; + + template <> + class numeric_limits + { + public: + static constexpr bool is_specialized = true; + + static constexpr long double min() { return LDBL_MIN; } + static constexpr long double max() { return LDBL_MAX; } + static constexpr long double lowest() { return -LDBL_MAX; } + + static constexpr int digits = LDBL_MANT_DIG; + static constexpr int digits10 = LDBL_DIG; + static constexpr int max_digits10 = LDBL_DECIMAL_DIG; + + static constexpr bool is_signed = true; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = FLT_RADIX; + static constexpr long double epsilon() { return LDBL_EPSILON; } + static constexpr long double round_error() { return 0.5L; } + + static constexpr int min_exponent = LDBL_MIN_EXP; + static constexpr int min_exponent10 = LDBL_MIN_10_EXP; + static constexpr int max_exponent = LDBL_MAX_EXP; + static constexpr int max_exponent10 = LDBL_MAX_10_EXP; + + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_present; + static constexpr bool has_denorm_loss = true; + static constexpr long double infinity() { return INFINITY; } + static constexpr long double quiet_NaN() { return NAN; } + static constexpr long double signaling_NaN() { return NAN; } + static constexpr long double denorm_min() { return LDBL_TRUE_MIN; } + + static constexpr bool is_iec559 = true; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = true; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; + }; +} diff --git a/include_std/memory b/include_std/memory new file mode 100644 index 00000000..bbccee81 --- /dev/null +++ b/include_std/memory @@ -0,0 +1,108 @@ +/* + 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 . +*/ + +#pragma once + +#include +#include +#include +#include + +namespace std +{ + template + struct allocation_result + { + Pointer ptr; + SizeType count; + }; + + template + struct allocator + { + public: + typedef T value_type; + typedef T *pointer; + typedef const T *const_pointer; + typedef T &reference; + typedef const T &const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef std::true_type propagate_on_container_move_assignment; + typedef std::true_type is_always_equal; + + template + struct rebind + { + typedef allocator other; + }; + + allocator() {} + allocator(const allocator &other) {} + template + allocator(const allocator &other) {} + ~allocator() {} + + pointer allocate(size_type n, const void *hint = 0) + { + return static_cast(::operator new(n * sizeof(T))); + } + + std::allocation_result allocate_at_least(std::size_t n) + { + if (n > max_size()) + return {nullptr, 0}; + return {allocate(n), n}; + } + + void deallocate(T *p, std::size_t n) + { + ::operator delete(p); + } + + size_type max_size() const + { + return std::numeric_limits::max() / sizeof(T); + } + + void construct(pointer p, const_reference val) + { + ::new ((void *)p) T(val); + } + + template + void construct(U *p, Args &&...args) + { + ::new ((void *)p) U(std::forward(args)...); + } + + void destroy(pointer p) { p->~T(); } + template + void destroy(U *p) { p->~U(); } + pointer address(reference x) const { return &x; } + const_pointer address(const_reference x) const { return &x; } + }; + + template + T *addressof(T &arg) + { + return reinterpret_cast(&const_cast(reinterpret_cast(arg))); + } + + template + const T *addressof(const T &&) = delete; +} diff --git a/include_std/mutex b/include_std/mutex index ee977f1e..40db4c47 100644 --- a/include_std/mutex +++ b/include_std/mutex @@ -25,7 +25,6 @@ namespace std { - struct defer_lock_t { explicit defer_lock_t() = default; diff --git a/include_std/ranges b/include_std/ranges new file mode 100644 index 00000000..2475e134 --- /dev/null +++ b/include_std/ranges @@ -0,0 +1,28 @@ +/* + 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 . +*/ + +#pragma once + +namespace std +{ + struct from_range_t + { + explicit from_range_t() = default; + }; + + inline constexpr std::from_range_t from_range{}; +} diff --git a/include_std/std/smart_ptr.hpp b/include_std/std/smart_ptr.hpp index 529b421e..9f4a7731 100644 --- a/include_std/std/smart_ptr.hpp +++ b/include_std/std/smart_ptr.hpp @@ -20,7 +20,7 @@ #include -#include +#include #include // show debug messages diff --git a/include_std/stdexcept b/include_std/stdexcept index c5aef13e..f0af076f 100644 --- a/include_std/stdexcept +++ b/include_std/stdexcept @@ -17,6 +17,8 @@ #pragma once +#include + namespace std { class runtime_error @@ -28,4 +30,14 @@ namespace std runtime_error(const char *what_arg) : m_what(what_arg) {} const char *what() const { return this->m_what; } }; + + class out_of_range + { + public: + out_of_range(const char *what_arg) + { + /* FIXME: This is a temporary assert */ + assert(what_arg != nullptr); + } + }; } diff --git a/include_std/type_trails b/include_std/type_traits similarity index 72% rename from include_std/type_trails rename to include_std/type_traits index 0def5633..f367fa0e 100644 --- a/include_std/type_trails +++ b/include_std/type_traits @@ -42,4 +42,17 @@ namespace std { typedef T type; }; + + template + struct integral_constant + { + static constexpr T value = v; + typedef T value_type; + typedef integral_constant type; + constexpr operator value_type() const noexcept { return value; } + constexpr value_type operator()() const noexcept { return value; } + }; + + typedef integral_constant true_type; + typedef integral_constant false_type; } diff --git a/include_std/utility b/include_std/utility index cad654cc..b3607381 100644 --- a/include_std/utility +++ b/include_std/utility @@ -17,7 +17,7 @@ #pragma once -#include +#include namespace std { diff --git a/include_std/vector b/include_std/vector index b9bdd9df..e528e7fa 100644 --- a/include_std/vector +++ b/include_std/vector @@ -19,7 +19,7 @@ #include -#include +#include #include #include #include