microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Classes | Namespaces
std_debug.hpp File Reference

reloco::Debug<T> specializations for heap-free standard library types. More...

#include <array>
#include <bitset>
#include <cstddef>
#include <functional>
#include <microfmt/microfmt.hpp>
Include dependency graph for std_debug.hpp:

Go to the source code of this file.

Classes

struct  reloco::Debug< std::array< T, N > >
 Debug<std::array<T, N>>: [val1, val2, ...], recursing into each element via microfmt::as_debug. N == 0 renders as []. More...
 
struct  reloco::Debug< std::bitset< N > >
 Debug<std::bitset<N>>: the bit string, MSB (index N - 1) first, matching std::bitset::operator<<'s own bit order – computed directly from test(i), with no to_string() allocation. More...
 
struct  reloco::Debug< std::reference_wrapper< T > >
 Debug<std::reference_wrapper<T>>: forwards directly to the referenced value's own as_debug() output, with no wrapper decoration – reference_wrapper is purely transparent. More...
 
struct  reloco::Debug< std::byte >
 Debug<std::byte>: a zero-padded lowercase hex byte, e.g. 0x2a – std::byte has no operator<</formatter of its own in the standard library either, so this picks the conventional raw-byte debug representation. More...
 

Namespaces

namespace  reloco
 

Detailed Description

reloco::Debug<T> specializations for heap-free standard library types.

Most builtins (int/char/bool/pointers/std::nullptr_t) and heap-free standard containers/wrappers (std::optional, std::variant, std::monostate, and every tuple-like type via formatters/tuple.hpp, which covers both std::pair and std::tuple) already get fully correct {:?}/as_debug() behavior for free, through their existing microfmt::formatter<T> specialization: as_debug()'s priority chain (Debug<T> -> formatter<T> -> Display<T>, see microfmt.hpp) only ever reaches formatter<T> when there is no Debug<T>, and those formatter<T> specializations already parse/honor the ? debug flag themselves (e.g. microfmt::string_view/char's own quoting, see format_parse_context::consume_debug_flag). Adding a Debug<T> for any of those types would be pure duplication – at best redundant, at worst a behavioral regression (since Debug<T> takes priority and ignores spec, it would silently stop honoring any format specifier the existing formatter<T> supports).

This header is only for standard types that have no formatter<T> (nor Display<T>) at all today, so as_debug()/{:?} would otherwise fail to compile for them:

Floating-point Debug<T> (float/double/long double) is deliberately not included here: see formatters/debug_float.hpp, a separate opt-in header (reloco/microfmt avoid floating point by default, see formatters/floating.hpp's own opt-in status).