From 919ad9d1022edec7fdd97f74ef50de26dde6aebb Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 5 Feb 2021 23:15:37 +0200 Subject: Add IntegerView --- libk/stdlib.h | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'libk/stdlib.h') diff --git a/libk/stdlib.h b/libk/stdlib.h index 44bacf4..f031408 100644 --- a/libk/stdlib.h +++ b/libk/stdlib.h @@ -4,27 +4,34 @@ #include class Console { -public: + public: virtual void write(char c) = 0; - virtual void write(const String &msg) = 0; - virtual void write(int n) = 0; - virtual void write(unsigned int n) = 0; + virtual void write(ViewIterator& msg) = 0; - static void set(Console *ptr); - static Console *get(); + static void set(Console* ptr); + static Console* get(); }; -template void printk(const T &a) { - if (auto *c = Console::get()) { - if constexpr (is_same()) - c->write(String(a)); - else +template +void printk(const T& a) { + if (auto* c = Console::get()) { + if constexpr (is_same()) { + c->write(a); + } else if constexpr (requires { StringView(a); }) { + StringView v(a); + auto iter = v.begin(); + c->write(iter); + } else if constexpr (requires { IntegerView(a); }) { + IntegerView v(a); + auto iter = v.begin(); + c->write(iter); + } else c->write(a); } } template -void printk(const T &a, const Args &...x) { +void printk(const T& a, const Args&... x) { printk(a); printk(x...); } -- cgit v1.2.1