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 <sstream>
10
13
14FMT_BEGIN_NAMESPACE
15template <>
16struct formatter<std::vector<uint8_t>>
17{
18 template <typename ParseContext>
19 constexpr auto parse(ParseContext& ctx)
20 {
21 return ctx.begin();
22 }
23
24 template <typename FormatContext>
25 auto format(const std::vector<uint8_t>& v, FormatContext& ctx) const
26 {
27 return format_to(
28 ctx.out(), "<vec[{}]: {:02x}>", v.size(), fmt::join(v, " "));
29 }
30};
31
32template <size_t N>
33struct formatter<std::array<uint8_t, N>>
34{
35 template <typename ParseContext>
36 constexpr auto parse(ParseContext& ctx)
37 {
38 return ctx.begin();
39 }
40
41 template <typename FormatContext>
42 auto format(const std::array<uint8_t, N>& a, FormatContext& ctx) const
43 {
44 return format_to(ctx.out(), "<arr[{}]: {:02x}>", N, fmt::join(a, " "));
45 }
46};
47FMT_END_NAMESPACE
STL namespace.
auto format(const std::array< uint8_t, N > &a, FormatContext &ctx) const
Definition std_formatters.h:42
constexpr auto parse(ParseContext &ctx)
Definition std_formatters.h:36
auto format(const std::vector< uint8_t > &v, FormatContext &ctx) const
Definition std_formatters.h:25
constexpr auto parse(ParseContext &ctx)
Definition std_formatters.h:19