Add random::generator formatter
This commit is contained in:
parent
c96766659c
commit
d42639edba
1 changed files with 22 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <format>
|
||||
|
||||
#include <psemek/random/device.hpp>
|
||||
|
||||
|
|
@ -66,6 +67,9 @@ namespace psemek::random
|
|||
read(stream, gen.inc_);
|
||||
}
|
||||
|
||||
template <typename T, typename Char>
|
||||
friend struct std::formatter;
|
||||
|
||||
private:
|
||||
std::uint64_t state_ = 0;
|
||||
std::uint64_t inc_ = 0;
|
||||
|
|
@ -78,3 +82,21 @@ namespace psemek::random
|
|||
};
|
||||
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <typename Char>
|
||||
struct formatter<::psemek::random::generator, Char>
|
||||
: formatter<std::uint64_t>
|
||||
{
|
||||
using base = formatter<std::uint64_t>;
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(::psemek::random::generator const & rng, FormatContext & ctx) const
|
||||
{
|
||||
return std::format_to(ctx.out(), "({}, {})", rng.state_, rng.inc_);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue