0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::fmt: Add bool support.

This commit is contained in:
Jason Volk 2017-04-02 20:53:14 -07:00
parent b579d7dfc3
commit 49da778def

View file

@ -106,11 +106,37 @@ decltype(string_specifier::types)
string_specifier::types
{};
struct bool_specifier
:specifier
{
static const std::tuple
<
bool,
char, unsigned char,
short, unsigned short,
int, unsigned int,
long, unsigned long
>
types;
bool operator()(char *&out, const size_t &max, const spec &, const arg &val) const override;
using specifier::specifier;
}
const bool_specifier
{
{ "b" }
};
decltype(bool_specifier::types)
bool_specifier::types
{};
struct signed_specifier
:specifier
{
static const std::tuple
<
bool,
char, unsigned char,
short, unsigned short,
int, unsigned int,
@ -135,6 +161,7 @@ struct unsigned_specifier
{
static const std::tuple
<
bool,
char, unsigned char,
short, unsigned short,
int, unsigned int,
@ -426,6 +453,47 @@ const
else return false;
}
bool
fmt::bool_specifier::operator()(char *&out,
const size_t &max,
const spec &,
const arg &val)
const
{
using karma::eps;
using karma::maxwidth;
static const auto throw_illegal([]
{
throw illegal("Failed to print signed value");
});
const auto closure([&](const bool &boolean)
{
using karma::maxwidth;
struct generator
:karma::grammar<char *, bool()>
{
karma::rule<char *, bool()> rule
{
karma::bool_
,"boolean"
};
generator(): generator::base_type{rule} {}
}
static const generator;
return karma::generate(out, maxwidth(max)[generator] | eps[throw_illegal], boolean);
});
return !until(types, [&](auto type)
{
return !visit_type<decltype(type)>(val, closure);
});
}
bool
fmt::signed_specifier::operator()(char *&out,
const size_t &max,