0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::fmt: Add bsprintf(): all-in-one printf and buffer.

This commit is contained in:
Jason Volk 2017-10-04 16:23:09 -07:00
parent 6c04739634
commit 87771b00ba

View file

@ -38,6 +38,7 @@ namespace ircd::fmt
struct vsnprintf;
struct snstringf;
struct vsnstringf;
template<size_t MAX> struct bsprintf;
//
// Module API
@ -191,3 +192,23 @@ struct ircd::fmt::snstringf
max, fmt, va_rtti{std::forward<args>(a)...}
}{}
};
template<size_t MAX>
struct ircd::fmt::bsprintf
:snprintf
,string_view
{
std::array<char, MAX> buf;
template<class... args>
bsprintf(const char *const &fmt,
args&&... a)
:snprintf
{
internal, buf.data(), buf.size(), fmt, va_rtti{std::forward<args>(a)...}
}
,string_view
{
buf.data(), size_t(static_cast<snprintf &>(*this))
}{}
};