microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
sbuf_sink.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace microfmt {
5
18template <typename SBufT> class RELOCO_POINTER sbuf_sink {
19public:
25 explicit constexpr sbuf_sink(SBufT *sb RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS) noexcept : m_sbuf(sb) {}
26
33 [[nodiscard]] sink as_sink() const noexcept RELOCO_LIFETIMEBOUND {
34 return sink{.ctx = m_sbuf, .write_fn = [](void *ctx, microfmt::string_view sv) noexcept {
35 auto *self = static_cast<SBufT *>(ctx);
36 if (!sv.empty()) {
37 // ADL / deferred lookup will resolve sbuf_bcat at instantiation
38 // time if <sys/sbuf.h> is included by the user.
39 sbuf_bcat(self, sv.data(), sv.size());
40 }
41 }};
42 }
43
49 [[nodiscard]] constexpr SBufT *native_handle() const noexcept { return m_sbuf; }
50
51private:
52 SBufT *m_sbuf;
53};
54
55} // namespace microfmt
Output sink that writes formatted characters into a FreeBSD-style sbuf.
Definition sbuf_sink.hpp:18
constexpr sbuf_sink(SBufT *sb RELOCO_LIFETIMEBOUND RELOCO_LIFETIME_CAPTURE_BY_THIS) noexcept
Constructs an sbuf sink over an existing buffer pointer.
Definition sbuf_sink.hpp:25
constexpr SBufT * native_handle() const noexcept
Returns the underlying sbuf pointer.
Definition sbuf_sink.hpp:49
sink as_sink() const noexcept RELOCO_LIFETIMEBOUND
Creates a type-erased sink adapter pointing to this instance.
Definition sbuf_sink.hpp:33
Core formatting primitives, sinks, and customization point.
Definition assert.hpp:19
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46