summaryrefslogtreecommitdiff
path: root/asl/format.hpp
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-10-11 00:32:49 +0200
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-12-20 15:35:58 +0100
commitf011d871ef3af26c8f4e19de2c8d781c601ceffb (patch)
treeac3611e6fa054cc0f8870aad524b263ff917057f /asl/format.hpp
parente020805cb140ed98d09e606a867b910fce78ad15 (diff)
Add console printing
Diffstat (limited to 'asl/format.hpp')
-rw-r--r--asl/format.hpp40
1 files changed, 15 insertions, 25 deletions
diff --git a/asl/format.hpp b/asl/format.hpp
index f17329f..b4cb439 100644
--- a/asl/format.hpp
+++ b/asl/format.hpp
@@ -2,23 +2,11 @@
#include "asl/integers.hpp"
#include "asl/meta.hpp"
-#include "asl/utility.hpp"
+#include "asl/io.hpp"
namespace asl
{
-// @Todo Move this to io
-class writer
-{
-public:
- writer() = default;
- ASL_DELETE_COPY_MOVE(writer);
- virtual ~writer() = default;
-
- // @Todo Use string view, or span of bytes?
- virtual void write(const char* str, int64_t len) = 0;
-};
-
class formatter;
template<typename T>
@@ -70,21 +58,21 @@ public:
};
// @Todo Use string_view
-template<typename... Args>
+template<formattable... Args>
void format(writer* w, const char* fmt, const Args&... args)
{
- format_internals::type_erased_arg type_erased_args[] = {
- format_internals::type_erased_arg(args)...
- };
-
- // @Todo Use array extent
- format_internals::format(w, fmt, type_erased_args, types_count<Args...>);
-}
+ if constexpr (types_count<Args...> > 0)
+ {
+ format_internals::type_erased_arg type_erased_args[] = {
+ format_internals::type_erased_arg(args)...
+ };
-// @Todo Use string_view
-inline void format(writer* w, const char* fmt)
-{
- format_internals::format(w, fmt, nullptr, 0);
+ format_internals::format(w, fmt, type_erased_args, types_count<Args...>);
+ }
+ else
+ {
+ format_internals::format(w, fmt, nullptr, 0);
+ }
}
template<int64_t N>
@@ -96,6 +84,8 @@ void AslFormat(formatter& f, const char (&str)[N])
void AslFormat(formatter& f, float);
void AslFormat(formatter& f, double);
+void AslFormat(formatter& f, bool);
+
void AslFormat(formatter& f, uint8_t);
void AslFormat(formatter& f, uint16_t);
void AslFormat(formatter& f, uint32_t);