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:
parent
6c04739634
commit
87771b00ba
1 changed files with 21 additions and 0 deletions
|
@ -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))
|
||||
}{}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue