Passing fmt_data to format_arg functions as constant expression
This commit is contained in:
parent
a0230a7e27
commit
9b430b9902
15
inc/format.h
15
inc/format.h
@ -41,20 +41,21 @@ constexpr inline void check_fmt_params() {
|
||||
*/
|
||||
|
||||
// TODO: Error handling
|
||||
template <std::integral arg_t>
|
||||
constexpr inline void format_arg(char* dest, fmt_data_t fmt_data, arg_t arg) {
|
||||
// constexpr auto error_array = get_init_array<fmt_data.length>('f');
|
||||
template <fmt_data_t fmt_data, std::integral arg_t>
|
||||
constexpr inline void format_arg(char* dest, arg_t arg) {
|
||||
auto error_array = get_init_array<fmt_data.length>('f');
|
||||
|
||||
detail::format_integral(dest, arg, fmt_data);
|
||||
};
|
||||
// TODO: Error handling
|
||||
template <std::floating_point arg_t>
|
||||
constexpr inline void format_arg(char* dest, fmt_data_t fmt_data, arg_t) {
|
||||
template <fmt_data_t fmt_data, std::floating_point arg_t>
|
||||
constexpr inline void format_arg(char* dest, arg_t) {
|
||||
*(dest) = 'f';
|
||||
*(dest + fmt_data.length - fmt_data.precision - 1) = '.';
|
||||
};
|
||||
// TODO: Error handling
|
||||
constexpr inline void format_arg(char* dest, fmt_data_t fmt_data, const char* arg) {
|
||||
template<fmt_data_t fmt_data>
|
||||
constexpr inline void format_arg(char* dest, const char* arg) {
|
||||
const std::size_t len = const_strlen(arg);
|
||||
if (len > fmt_data.length) return;
|
||||
|
||||
@ -77,7 +78,7 @@ constexpr inline void format_args(char*) {
|
||||
|
||||
template <auto fmt_data_array, typename first_arg_t, typename... args_t>
|
||||
constexpr inline void format_args(char* dest, first_arg_t first_arg, args_t... args) {
|
||||
format_arg(dest + fmt_data_array[0].position, fmt_data_array[0], 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...);
|
||||
}
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ constexpr inline void format_integral(char* out, uint_t value,
|
||||
|
||||
|
||||
template <std::floating_point float_t>
|
||||
constexpr inline void format_integral(char* out, float_t value,
|
||||
constexpr inline void format_floating_point(char* out, float_t value,
|
||||
fmt_data_t fmt_node) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@ -18,18 +18,8 @@ constexpr inline std::size_t const_pow(std::size_t base, std::size_t pow) {
|
||||
}
|
||||
|
||||
|
||||
//template <std::size_t t_n>
|
||||
//constexpr std::array<char, t_n> get_zero_array() {
|
||||
// std::array<char, t_n> result;
|
||||
//
|
||||
// for (auto& c : result)
|
||||
// c = '0';
|
||||
//
|
||||
// return result;
|
||||
//}
|
||||
|
||||
template <std::size_t t_n>
|
||||
constexpr inline std::array<char, t_n> get_init_array(char val) {
|
||||
consteval inline std::array<char, t_n> get_init_array(char val) {
|
||||
std::array<char, t_n> result;
|
||||
|
||||
for (auto& c : result)
|
||||
@ -38,21 +28,6 @@ constexpr inline std::array<char, t_n> get_init_array(char val) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//template <fmt_node_t fmt_node>
|
||||
//constexpr std::array<char, fmt_node.length> get_init_array() {
|
||||
// std::array<char, fmt_node.length> result;
|
||||
//
|
||||
// if constexpr (fmt_node.has_zero_padding) {
|
||||
// for (auto& c : result)
|
||||
// c = '0';
|
||||
// } else {
|
||||
// for (auto& c : result)
|
||||
// c = ' ';
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
//}
|
||||
|
||||
|
||||
template <auto ast>
|
||||
consteval inline std::size_t count_ast_format_nodes() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user