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

Traits-based, type-erased sink provider customization point. More...

#include "microfmt.hpp"
#include <type_traits>
#include <utility>
Include dependency graph for sink_provider.hpp:

Go to the source code of this file.

Classes

struct  microfmt::detail::has_sink_provider_flush< Tag, typename >
 
struct  microfmt::detail::has_sink_provider_flush< Tag, std::void_t< decltype(sink_provider_traits< Tag >::flush(std::declval< value_ref< typename sink_provider_traits< Tag >::context_type > >()))> >
 
struct  microfmt::detail::has_stateless_sink_provider_flush< Tag, typename >
 
struct  microfmt::detail::has_stateless_sink_provider_flush< Tag, std::void_t< decltype(sink_provider_traits< Tag >::flush())> >
 
class  microfmt::sink_provider_ref
 Type-erased, two-word handle to a sink backend. More...
 
struct  microfmt::sink_provider_ref::vtable
 Virtual table of sink operations. More...
 
class  microfmt::sink_provider< Tag >
 Owning wrapper: holds context_type by value, sharing lifetime with the handle obtained from ref. More...
 
struct  microfmt::null_sink_provider_tag
 Tag for a stateless sink that discards every write. More...
 
struct  microfmt::sink_provider_traits< null_sink_provider_tag >
 
struct  microfmt::span_sink_provider_tag
 Tag for a stateful sink that appends into a fixed-size microfmt::span of character storage, truncating writes that exceed its remaining capacity. More...
 
struct  microfmt::span_sink_provider_context
 
struct  microfmt::sink_provider_traits< span_sink_provider_tag >
 

Namespaces

namespace  microfmt
 
namespace  microfmt::detail
 

Detailed Description

Traits-based, type-erased sink provider customization point.

Mirrors reloco's context_type-based provider pattern (see reloco's docs/extending.md, "Extending reloco: the context_type-based provider pattern", which is itself adapted from microfmt): an empty tag selects a sink_provider_traits<Tag> specialization declaring a context_type and static operations; a typed sink_provider<Tag> wrapper or caller-owned context object holds that state by value; and the type-erased sink_provider_ref borrows it for use in non-templated code. No virtual interfaces, no allocation, and no runtime registration are involved.

This is an additive customization point alongside the hand-written as_sink() methods already on span_sink, buffer_sink, and friends (see microfmt.hpp) – it exists for backends that want the same boilerplate reloco's allocator_ref gets (mandatory/optional operation detection, stateless-vs-stateful tag dispatch) instead of writing a context pointer + lambda pair by hand. Both shapes ultimately produce an ordinary microfmt::sink, so either can be passed to format_to/ vformat_to interchangeably.