Moved get_init_array() to utility.h

This commit is contained in:
Andreas Tsouchlos 2021-11-22 11:21:29 +01:00
parent 12eec70058
commit 0557bd1651
3 changed files with 21 additions and 17 deletions

View File

@ -32,23 +32,6 @@ constexpr int get_output_len() {
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;
}
// TODO: See if this is possible with <charconv>
template <fmt_node_t fmt_node, std::integral arg_t>
constexpr std::array<char, fmt_node.length> format_arg(arg_t arg) {

View File

@ -2,6 +2,9 @@
#define LOGGER_PARSE_TYPES_H
#include <array>
namespace detail {

View File

@ -4,6 +4,8 @@
#include <cstdlib>
#include "parse_types.h"
namespace detail {
@ -16,6 +18,22 @@ constexpr std::size_t const_pow(std::size_t base, std::size_t pow) {
}
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;
}
} // namespace detail