6 Commits

View File

@@ -36,6 +36,13 @@ using size_t = uint16_t;
*/
// various
constexpr inline bool is_constant_evaluated() noexcept {
return __builtin_is_constant_evaluated();
}
struct true_type {
constexpr static bool value = true;
};
@@ -45,6 +52,35 @@ struct false_type {
};
// is_same
template <typename fist_t, typename second_t>
struct is_same : public false_type {};
template <typename type_t>
struct is_same<type_t, type_t> : public true_type {};
// is_one_of
template <typename...>
struct is_one_of;
template <typename type_t>
struct is_one_of<type_t> {
constexpr static bool value = false;
};
template <typename type_t, typename first_t, typename... rest_t>
struct is_one_of<type_t, first_t, rest_t...> {
constexpr static bool value = std::is_same<type_t, first_t>::value ||
is_one_of<type_t, rest_t...>::value;
};
// remove_x
// clang-format off
template <typename type_t> struct remove_cv { typedef type_t type; };
@@ -67,47 +103,41 @@ template <typename type_t> using remove_cv_t = typename std::remove_cv<ty
template <typename type_t> using remove_const_t = typename std::remove_const<type_t>::type;
template <typename type_t> using remove_volatile_t = typename std::remove_volatile<type_t>::type;
// clang-format on
template <typename> struct is_integral_helper : public false_type {};
template <> struct is_integral_helper<bool> : public true_type {};
template <> struct is_integral_helper<char> : public true_type {};
template <> struct is_integral_helper<signed char> : public true_type {};
template <> struct is_integral_helper<unsigned char> : public true_type {};
template <> struct is_integral_helper<wchar_t> : public true_type {};
template <> struct is_integral_helper<char16_t> : public true_type {};
template <> struct is_integral_helper<char32_t> : public true_type {};
template <> struct is_integral_helper<short> : public true_type {};
template <> struct is_integral_helper<unsigned short> : public true_type {};
template <> struct is_integral_helper<int> : public true_type {};
template <> struct is_integral_helper<unsigned int> : public true_type {};
template <> struct is_integral_helper<long> : public true_type {};
template <> struct is_integral_helper<unsigned long> : public true_type {};
template <> struct is_integral_helper<long long> : public true_type {};
template <> struct is_integral_helper<unsigned long long> : public true_type {};
// is_integral
template <typename type_t>
struct is_integral
: public is_integral_helper<remove_cv_t<type_t>> {};
using is_integral =
is_one_of<remove_cv_t<type_t>, bool, char, signed char, unsigned char,
wchar_t, char16_t, char32_t, short, unsigned short, int,
unsigned int, long, unsigned long, long long, unsigned long long>;
template <typename> struct is_floating_point_helper : public false_type {};
// is_signed
template<> struct is_floating_point_helper<float> : public true_type {};
template<> struct is_floating_point_helper<double> : public true_type {};
template<> struct is_floating_point_helper<long double> : public true_type {};
template<typename _Tp>
struct is_floating_point
: public is_floating_point_helper<remove_cv_t<_Tp>>::type {};
template <typename _Tp>
using is_signed_integer = is_one_of<remove_cv_t<_Tp>, signed char, signed short,
signed int, signed long, signed long long>;
constexpr inline bool is_constant_evaluated() noexcept {
return __builtin_is_constant_evaluated();
}
// is_floating_point
template <typename type_t>
using is_floating_point =
is_one_of<remove_cv_t<type_t>, float, double, long double>;
// make_unsigned
// clang-format off
template <typename type_t> struct make_unsigned { using type = type_t; };
template <> struct make_unsigned<signed char> { using type = char; };
@@ -119,6 +149,16 @@ template <> struct make_unsigned<signed long long> { using type = unsigned long
// clang-format on
// value definitions
template <typename type_t>
inline constexpr bool is_integral_v = is_integral<type_t>::value;
template <typename type_t>
inline constexpr bool is_signed_integer_v = is_signed_integer<type_t>::value;
template <typename type_t>
inline constexpr bool is_floating_point_v = is_floating_point<type_t>::value;
/*
*
* concepts
@@ -126,17 +166,17 @@ template <> struct make_unsigned<signed long long> { using type = unsigned long
*/
// template <typename _Tp>
// concept integral = is_integral_v<_Tp>;
//
// template <typename _Tp>
// concept signed_integral = integral<_Tp> && is_signed_v<_Tp>;
//
// template <typename _Tp>
// concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>;
//
// template <typename _Tp>
// concept floating_point = is_floating_point_v<_Tp>;
template <typename type_t>
concept integral = is_integral_v<type_t>;
template <typename type_t>
concept signed_integral = is_signed_integer_v<type_t>;
template <typename type_t>
concept unsigned_integral = integral<type_t> && !signed_integral<type_t>;
template <typename type_t>
concept floating_point = is_floating_point_v<type_t>;
/*
@@ -147,8 +187,10 @@ template <> struct make_unsigned<signed long long> { using type = unsigned long
template <typename input_t, typename output_t>
void copy(input_t* start, input_t* end, output_t* dest_start) {
memcpy(start, dest_start, end - start);
constexpr inline void copy(const input_t* start, const input_t* end, output_t* dest_start) {
auto temp = start;
while (temp != end)
*(dest_start++) = *(temp++);
}
@@ -165,7 +207,7 @@ std::remove_reference_t<T>&& move(T&& arg) noexcept {
}
template <typename T>
void swap(T& t1, T& t2) {
constexpr inline void swap(T& t1, T& t2) {
T temp = std::move(t1);
t1 = std::move(t2);
t2 = std::move(temp);
@@ -195,13 +237,10 @@ public:
}
constexpr array() noexcept = default;
constexpr array(array&) = default;
constexpr array(const array&) = default;
constexpr array(array&&) = default;
constexpr array& operator=(array& other) = default;
constexpr array& operator=(const array& other) = default;
constexpr array& operator=(array&& other) = default;
constexpr void swap(array<data_t, t_size>& other) noexcept {
@@ -232,6 +271,14 @@ public:
return (&(m_data[t_size - 1]) + 1);
}
constexpr const_iterator begin() const noexcept {
return &(m_data[0]);
}
constexpr const_iterator end() const noexcept {
return (&(m_data[t_size - 1]) + 1);
}
constexpr const_iterator cbegin() const noexcept {
return &(m_data[0]);
}