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

Core formatting primitives, sinks, and customization point. More...

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <string_view>
#include <tuple>
#include <type_traits>
#include "detail/assert.hpp"
#include "detail/compat.hpp"
#include "reloco.hpp"
#include <reloco/fmt.hpp>
#include "microfmt.ipp"
Include dependency graph for microfmt.hpp:

Go to the source code of this file.

Classes

class  microfmt::span_sink
 Output sink that writes formatted characters into a fixed-size contiguous memory buffer. More...
 
class  microfmt::buffer_sink< N >
 Output sink that stores formatted characters in an internal fixed-size stack/inline buffer. More...
 
class  microfmt::iterator_sink< OutputIt >
 Output sink adapter for arbitrary output iterators or raw pointers. More...
 
class  microfmt::counting_sink
 Output sink that counts total formatted bytes without storing characters. More...
 
class  microfmt::null_sink
 Null/Discard sink that discards all formatted output. More...
 
struct  microfmt::detail::c_string_sink_base
 
class  microfmt::c_string_sink< N >
 Output sink that guarantees a null-terminated string within a fixed-size buffer. More...
 
class  microfmt::callback_sink< Callable >
 Output sink that adapts any callable object (lambda, functor) to a sink. More...
 
class  microfmt::format_parse_context
 
struct  microfmt::formatter< microfmt::string_view >
 
struct  microfmt::formatter< std::string_view >
 
struct  microfmt::detail::const_char_like
 
struct  microfmt::formatter< const char * >
 
struct  microfmt::formatter< char[N]>
 
struct  microfmt::formatter< const char[N]>
 
struct  microfmt::formatter< char * >
 
struct  microfmt::detail::int_formatter_specs
 
struct  microfmt::detail::int_formatter_specs::flags_t
 
struct  microfmt::formatter< T, std::enable_if_t< std::is_integral_v< T > &&!std::is_same_v< T, bool > &&!std::is_same_v< T, char > > >
 
struct  microfmt::formatter< char >
 
struct  microfmt::formatter< bool >
 
struct  microfmt::detail::raw_ptr_format
 
struct  microfmt::formatter< T *, std::enable_if_t<!std::is_same_v< T, const char > &&!std::is_same_v< T, char > > >
 
struct  microfmt::formatter< std::nullptr_t >
 
struct  microfmt::detail::has_formatter< T, typename >
 Detects whether formatter<T> has been given a definition (as opposed to just matching the template <typename T, typename Enable = void> struct formatter; forward declaration), using the standard decltype(sizeof(T)) completeness-detection idiom: sizeof of an incomplete type in the immediate context of a partial specialization's template argument substitution is a SFINAE failure, not a hard error. More...
 
struct  microfmt::detail::has_formatter< T, std::void_t< decltype(sizeof(formatter< T >))> >
 
struct  microfmt::detail::element_formatter< T >
 Drop-in replacement for a formatter<T> underlying_formatter; member used by container/wrapper formatters (reloco.hpp, tuple.hpp, map_view.hpp, filter_view.hpp, ranges.hpp, variant.hpp, ...) to format their elements/keys/values. More...
 
struct  microfmt::detail::element_formatter< T >::no_formatter_stub
 
struct  microfmt::detail::fix_type< T >
 Collapses argument types to a canonical representative before they reach format_type_table, so that types differing only in ways that format_type_thunk doesn't actually care about don't each generate their own thunk/table instantiation. More...
 
struct  microfmt::detail::fix_type< char[N]>
 
struct  microfmt::detail::fix_type< const char[N]>
 
struct  microfmt::detail::format_type_table< Args >
 
struct  microfmt::detail::format_type_table<>
 
struct  microfmt::detail::compiled_piece
 
struct  microfmt::detail::compiled_format< MaxPieces >
 
struct  microfmt::detail::compiled_string_storage< StrProvider >
 
struct  microfmt::detail::debug_view< T >
 Non-owning wrapper produced by as_debug, carrying no state of its own beyond a reference to the wrapped value; all the priority logic lives in formatter<debug_view<T>>::format below. More...
 
struct  microfmt::formatter< detail::debug_view< T > >
 
struct  microfmt::formatter< detail::debug_view< T > >::no_formatter_stub
 
struct  microfmt::compile_string_holder< Provider >
 
struct  microfmt::format_args
 Type-erased, non-owning view of formatting arguments. More...
 
struct  microfmt::detail::format_args_store< Args >
 Stack storage for type-erased argument pointers. More...
 
struct  microfmt::detail::format_args_store<>
 

Namespaces

namespace  microfmt
 
namespace  microfmt::detail
 

Macros

#define MICROFMT_STRING(s)
 

Typedefs

using microfmt::sink = reloco::sink
 Type-erased, zero-allocation output sink.
 
using microfmt::format_fn_t = void(*)(const void *val_ptr, microfmt::string_view spec, const sink &out) noexcept
 
template<typename T >
using microfmt::detail::microfmt_remove_cvref_t = std::remove_cv_t< std::remove_reference_t< T > >
 
template<typename T >
using microfmt::detail::fix_type_t = typename fix_type< T >::type
 

Functions

template<typename Callable >
constexpr callback_sink< Callable > microfmt::make_callback_sink (Callable &fn RELOCO_LIFETIMEBOUND) noexcept
 Helper factory function to construct a callback_sink with template deduction.
 
template<typename UInt >
RELOCO_ALWAYS_INLINE RELOCO_UNSAFE_BUFFER_USAGE RELOCO_CONSTEXPR20 char * microfmt::detail::format_dec_backward (char *ptr, UInt value) noexcept
 
template<typename UInt >
RELOCO_UNSAFE_BUFFER_USAGE RELOCO_ALWAYS_INLINE RELOCO_CONSTEXPR20 char * microfmt::detail::format_hex_backward (char *ptr, UInt value, bool uppercase) noexcept
 
RELOCO_BEGIN_UNSAFE_CODE RELOCO_ALWAYS_INLINE void microfmt::detail::emit_formatted_int (const sink &out, const char *digits, size_t digits_len, bool is_negative, microfmt::string_view prefix, uint8_t width, bool zero_pad) noexcept
 
template<typename T >
RELOCO_BEGIN_UNSAFE_CODE void microfmt::detail::format_type_thunk (const void *val_ptr, microfmt::string_view spec, const sink &out) noexcept
 
constexpr bool microfmt::detail::starts_with (microfmt::string_view sv, microfmt::string_view prefix) noexcept
 
constexpr bool microfmt::detail::starts_with (microfmt::string_view sv, char c) noexcept
 
RELOCO_BEGIN_UNSAFE_CODE constexpr bool microfmt::detail::parse_positional_index (microfmt::string_view text, size_t &index) noexcept
 
template<size_t MaxPieces = 32>
constexpr compiled_format< MaxPieces > microfmt::detail::compile_format_string (microfmt::string_view str) noexcept
 
template<size_t TargetIdx, size_t CurIdx, typename T , typename... Rest>
RELOCO_BEGIN_UNSAFE_CODE RELOCO_ALWAYS_INLINE const void * microfmt::detail::get_arg_by_index (const T &first, const Rest &...rest) noexcept
 
template<typename StrProvider , size_t PieceIdx, typename... Args>
RELOCO_ALWAYS_INLINE void microfmt::detail::emit_piece_by_index (const sink &out, const std::tuple< const Args &... > &arg_tuple) noexcept
 
template<typename StrProvider , typename... Args, size_t... Is>
RELOCO_ALWAYS_INLINE void microfmt::detail::unrolled_format_impl (const sink &out, std::index_sequence< Is... >, const Args &...args) noexcept
 
template<typename T >
constexpr auto microfmt::as_debug (const T &value RELOCO_LIFETIMEBOUND) noexcept
 Wraps value so it always renders through reloco's Debug<T> customization point when one exists, matching Rust's {:?}.
 
template<typename T , std::enable_if_t<!std::is_lvalue_reference_v< T >, int > = 0>
constexpr auto microfmt::as_debug (T &&) noexcept=delete
 
MICROFMT_API void microfmt::vformat_to (const sink &out, const microfmt::string_view fmt, const span< const void *const > arg_ptrs, const span< const format_fn_t > arg_fns) noexcept
 
template<typename... Args>
RELOCO_CONSTEXPR20 void microfmt::format_to (const sink &out, microfmt::string_view fmt, const Args &...args) noexcept
 
template<typename OutputIt , typename... Args>
RELOCO_CONSTEXPR20 OutputIt microfmt::format_to (OutputIt it, microfmt::string_view fmt, const Args &...args) noexcept
 
template<size_t N, typename... Args>
RELOCO_CONSTEXPR20 buffer_sink< N > microfmt::format (microfmt::string_view fmt, const Args &...args) noexcept
 
template<typename StrProvider , typename... Args>
RELOCO_CONSTEXPR20 void microfmt::format_to (const sink &out, compile_string_holder< StrProvider >, const Args &...args) noexcept
 
template<typename OutputIt , typename StrProvider , typename... Args>
RELOCO_CONSTEXPR20 OutputIt microfmt::format_to (OutputIt it, compile_string_holder< StrProvider > fmt, const Args &...args) noexcept
 
template<size_t N, typename StrProvider , typename... Args>
RELOCO_CONSTEXPR20 buffer_sink< N > microfmt::format (compile_string_holder< StrProvider > fmt, const Args &...args) noexcept
 
template<typename TargetContainer , typename... Args>
TargetContainer microfmt::format_as (string_view fmt, const Args &...args)
 Formats arguments into a newly constructed container (e.g., std::string) using a runtime format string.
 
template<typename TargetContainer , typename StrProvider , typename... Args>
TargetContainer microfmt::format_as (compile_string_holder< StrProvider > fmt, const Args &...args)
 Formats arguments into a newly constructed container using a compile-time checked format string holder.
 
template<typename... Args>
RELOCO_CONSTEXPR20 auto microfmt::make_format_args (const Args &...args RELOCO_LIFETIMEBOUND) noexcept
 Captures arguments into a type-erased storage object.
 
void microfmt::vformat_args_to (const sink &out, microfmt::string_view fmt, format_args args) noexcept
 Type-erased formatting engine entry point.
 
template<typename TargetContainer >
TargetContainer microfmt::vformat_args_as (microfmt::string_view fmt, format_args args)
 Formats type-erased arguments into a newly constructed container (e.g., std::string).
 

Variables

template<typename T >
constexpr bool microfmt::detail::has_formatter_v = has_formatter<T>::value
 

Detailed Description

Core formatting primitives, sinks, and customization point.

Macro Definition Documentation

◆ MICROFMT_STRING

#define MICROFMT_STRING (   s)
Value:
([] { \
struct str_provider { \
static constexpr microfmt::string_view get() noexcept { return microfmt::string_view{s, sizeof(s) - 1}; } \
}; \
return ::microfmt::compile_string_holder<str_provider>{}; \
}())