CCF
Loading...
Searching...
No Matches
std_formatters.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/ds/hex.h"
6
7#define FMT_HEADER_ONLY
8#include <fmt/format.h>
9#include <fmt/ranges.h>
10#include <sstream>
11
14
15FMT_BEGIN_NAMESPACE
16template <>
17struct formatter<std::vector<uint8_t>>
18{
19 template <typename ParseContext>
20 constexpr auto parse(ParseContext& ctx)
21 {
22 return ctx.begin();
23 }
24
25 template <typename FormatContext>
26 auto format(const std::vector<uint8_t>& v, FormatContext& ctx) const
27 {
28 return fmt::format_to(
29 ctx.out(), "<vec[{}]: {:02x}>", v.size(), fmt::join(v, " "));
30 }
31};
32
33template <size_t N>
34struct formatter<std::array<uint8_t, N>>
35{
36 template <typename ParseContext>
37 constexpr auto parse(ParseContext& ctx)
38 {
39 return ctx.begin();
40 }
41
42 template <typename FormatContext>
43 auto format(const std::array<uint8_t, N>& a, FormatContext& ctx) const
44 {
45 return fmt::format_to(ctx.out(), "<arr[{}]: {:02x}>", N, fmt::join(a, " "));
46 }
47};
48FMT_END_NAMESPACE
STL namespace.
auto format(const std::array< uint8_t, N > &a, FormatContext &ctx) const
Definition std_formatters.h:43
constexpr auto parse(ParseContext &ctx)
Definition std_formatters.h:37
auto format(const std::vector< uint8_t > &v, FormatContext &ctx) const
Definition std_formatters.h:26
constexpr auto parse(ParseContext &ctx)
Definition std_formatters.h:20