diff --git a/ostd/io.hh b/ostd/io.hh index 891489c..58f2933 100644 --- a/ostd/io.hh +++ b/ostd/io.hh @@ -142,18 +142,24 @@ static FileStream err(::stderr); /* no need to call anything from FileStream, prefer simple calls... */ -inline void write(const char *s) { - fputs(s, ::stdout); -} +namespace detail { + struct IoNat {}; -template -inline void write(const AnyString &s) { - fwrite(s.data(), 1, s.size(), ::stdout); + inline void write_impl(ConstCharRange s) { + fwrite(&s[0], 1, s.size(), ::stdout); + } + + template + inline void write_impl(const T &v, EnableIf< + !IsConstructible::value, detail::IoNat + > = detail::IoNat()) { + write(ostd::to_string(v)); + } } template inline void write(const T &v) { - write(ostd::to_string(v)); + detail::write_impl(v); } template @@ -162,20 +168,10 @@ inline void write(const T &v, const A &...args) { write(args...); } -inline void writeln(const char *s) { - write(s); - putc('\n', ::stdout); -} - -template -inline void writeln(const AnyString &s) { - write(s); - putc('\n', ::stdout); -} - template inline void writeln(const T &v) { - writeln(ostd::to_string(v)); + write(v); + putc('\n', ::stdout); } template @@ -197,7 +193,7 @@ namespace detail { } template -inline void writef(const char *fmt, const A &...args) { +inline void writef(ConstCharRange fmt, const A &...args) { char buf[512]; Ptrdiff need = format(detail::FormatOutRange(buf), fmt, args...); @@ -212,21 +208,8 @@ inline void writef(const char *fmt, const A &...args) { fwrite(s.data(), 1, need, ::stdout); } -template -inline void writef(const AnyString &fmt, - const A &...args) { - writef(fmt.data(), args...); -} - template -inline void writefln(const char *fmt, const A &...args) { - writef(fmt, args...); - putc('\n', ::stdout); -} - -template -inline void writefln(const AnyString &fmt, - const A &...args) { +inline void writefln(ConstCharRange fmt, const A &...args) { writef(fmt, args...); putc('\n', ::stdout); }