10 Commits

3 changed files with 110 additions and 60 deletions

View File

@@ -66,16 +66,13 @@ constexpr inline void format_arg(char* dest, const char* arg) {
}; };
// End of recursion
template <auto ast>
constexpr inline void format_args(char*) {
}
template <auto fmt_data_array, typename first_arg_t, typename... args_t> template <auto fmt_data_array, typename first_arg_t, typename... args_t>
constexpr inline void format_args(char* dest, first_arg_t first_arg, constexpr inline void format_args(char* dest, first_arg_t first_arg,
args_t... args) { args_t... args) {
format_arg<fmt_data_array[0]>(dest + fmt_data_array[0].position, first_arg); format_arg<fmt_data_array[0]>(dest + fmt_data_array[0].position, first_arg);
format_args<drop_first(fmt_data_array)>(dest, args...);
if constexpr(fmt_data_array.size() > 1)
format_args<drop_first(fmt_data_array)>(dest, args...);
} }

View File

@@ -51,7 +51,9 @@ inline int do_count_digits_decimal(uint64_t n) {
6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10,
10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15, 15, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15, 15,
15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 20}; 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 20};
auto t = bsr2log10[__builtin_clzll(n | 1) ^ 63];
auto t = bsr2log10[__builtin_clzll(n | 1) ^ 63];
static constexpr const uint64_t zero_or_powers_of_10[] = { static constexpr const uint64_t zero_or_powers_of_10[] = {
0, 0, FMT_POWERS_OF_10(1U), FMT_POWERS_OF_10(1000000000ULL), 0, 0, FMT_POWERS_OF_10(1U), FMT_POWERS_OF_10(1000000000ULL),
10000000000000000000ULL}; 10000000000000000000ULL};
@@ -80,9 +82,9 @@ constexpr inline auto count_digits_base(uint64_t n) -> int {
return (result + count_digits_base<FormatType::b>(n)); return (result + count_digits_base<FormatType::b>(n));
} else { } else {
if (!std::is_constant_evaluated()) { // if (!std::is_constant_evaluated()) {
return do_count_digits_decimal(n); // return do_count_digits_decimal(n);
} // }
return count_digits_decimal_fallback(n); return count_digits_decimal_fallback(n);
} }
} }
@@ -161,7 +163,7 @@ constexpr inline void format_base(char* out, uint_t value, int n_digits,
} }
if (value < divisor) { if (value < divisor) {
*--out = digits2_base<t_format_type>(value*divisor)[0]; *--out = digits2_base<t_format_type>(value * divisor)[0];
return; return;
} }

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 { struct true_type {
constexpr static bool value = true; 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 // clang-format off
template <typename type_t> struct remove_cv { typedef type_t type; }; 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_const_t = typename std::remove_const<type_t>::type;
template <typename type_t> using remove_volatile_t = typename std::remove_volatile<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 {}; // is_integral
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 {};
template <typename type_t> template <typename type_t>
struct is_integral using is_integral =
: public is_integral_helper<remove_cv_t<type_t>> {}; 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> template <typename _Tp>
struct is_floating_point using is_signed_integer = is_one_of<remove_cv_t<_Tp>, signed char, signed short,
: public is_floating_point_helper<remove_cv_t<_Tp>>::type {}; signed int, signed long, signed long long>;
constexpr inline bool is_constant_evaluated() noexcept { // is_floating_point
return __builtin_is_constant_evaluated();
}
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 <typename type_t> struct make_unsigned { using type = type_t; };
template <> struct make_unsigned<signed char> { using type = char; }; 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 // 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 * concepts
@@ -126,17 +166,17 @@ template <> struct make_unsigned<signed long long> { using type = unsigned long
*/ */
// template <typename _Tp> template <typename type_t>
// concept integral = is_integral_v<_Tp>; concept integral = is_integral_v<type_t>;
//
// template <typename _Tp> template <typename type_t>
// concept signed_integral = integral<_Tp> && is_signed_v<_Tp>; concept signed_integral = is_signed_integer_v<type_t>;
//
// template <typename _Tp> template <typename type_t>
// concept unsigned_integral = integral<_Tp> && !signed_integral<_Tp>; concept unsigned_integral = integral<type_t> && !signed_integral<type_t>;
//
// template <typename _Tp> template <typename type_t>
// concept floating_point = is_floating_point_v<_Tp>; concept floating_point = is_floating_point_v<type_t>;
/* /*
@@ -147,8 +187,11 @@ template <> struct make_unsigned<signed long long> { using type = unsigned long
template <typename input_t, typename output_t> template <typename input_t, typename output_t>
void copy(input_t* start, input_t* end, output_t* dest_start) { constexpr inline void copy(const input_t* start, const input_t* end,
memcpy(start, dest_start, end - start); output_t* dest_start) {
auto temp = start;
while (temp != end)
*(dest_start++) = *(temp++);
} }
@@ -165,7 +208,7 @@ std::remove_reference_t<T>&& move(T&& arg) noexcept {
} }
template <typename T> template <typename T>
void swap(T& t1, T& t2) { constexpr inline void swap(T& t1, T& t2) {
T temp = std::move(t1); T temp = std::move(t1);
t1 = std::move(t2); t1 = std::move(t2);
t2 = std::move(temp); t2 = std::move(temp);
@@ -194,14 +237,11 @@ public:
static_assert(sizeof...(args) == t_size, "Invalid number of arguments"); static_assert(sizeof...(args) == t_size, "Invalid number of arguments");
} }
constexpr array() noexcept = default; constexpr array() noexcept = default;
constexpr array(const array&) = default;
constexpr array(array&) = default; constexpr array(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 array& operator=(array&& other) = default;
constexpr void swap(array<data_t, t_size>& other) noexcept { constexpr void swap(array<data_t, t_size>& other) noexcept {
@@ -211,6 +251,9 @@ public:
} }
} }
constexpr std::size_t size() const noexcept {
return t_size;
}
constexpr data_t& operator[](std::size_t index) noexcept { constexpr data_t& operator[](std::size_t index) noexcept {
return m_data[index]; return m_data[index];
@@ -232,6 +275,14 @@ public:
return (&(m_data[t_size - 1]) + 1); 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 { constexpr const_iterator cbegin() const noexcept {
return &(m_data[0]); return &(m_data[0]);
} }