<xstd/misc/format/digest.hpp>¶
std::formatter<boost::hash2::digest<N>>¶
template<size_t N>
struct formatter<boost::hash2::digest<N>>;
Formats a Boost.Hash2 digest, such as the result of xxh3_128 or of xstd::digest, as hexadecimal.
Format specification¶
| Specification | Output |
|---|---|
empty, or x |
two lowercase hexadecimal digits per byte, in byte order |
X |
two uppercase hexadecimal digits per byte, in byte order |
Member functions¶
parse:- Effects: Accepts an empty specification,
xorX. - Throws:
format_errorfor any other specification. Built with exceptions off, as under-fno-exceptions, it writes the message tostderrand callsstd::abort()instead, as libstdc++'s and libc++'s own formatters do.
- Effects: Accepts an empty specification,
format:- Effects: Writes two hexadecimal digits per byte, in byte order, lowercase unless the specification is
X.
- Effects: Writes two hexadecimal digits per byte, in byte order, lowercase unless the specification is
Example¶
Adapted from the example of std::formatter on
cppreference.com, at
revision 177164, by
cppreference.com contributors. This example is under
CC-BY-SA 3.0 and the GFDL, as cppreference.com's content is; the rest of this
page is under the Boost Software License.
#include <xstd/misc/format/digest.hpp> // formatter
#include <boost/hash2/digest.hpp> // digest
#include <format> // format
#include <iostream> // cout
auto main() -> int
{
auto const a = boost::hash2::digest<1>({0xbe});
auto const b = boost::hash2::digest<4>({0xde, 0xad, 0xbe, 0xef});
std::cout << std::format("To {0} or not to {0}, that is {1}.\n", a, b);
std::cout << std::format("To {0:x} or not to {0:x}, that is {1:x}.\n", a, b);
std::cout << std::format("To {0:X} or not to {0:X}, that is {1:X}.\n", a, b);
}
Output:
To be or not to be, that is deadbeef.
To be or not to be, that is deadbeef.
To BE or not to BE, that is DEADBEEF.
See also¶
| Entity | Relation |
|---|---|
digest |
the class whose result this formats |
std::formatter |
the standard's formatter, which this specializes |