9#include "../microfmt.hpp"
20 static_assert(N > 0,
"tee_sink must have at least one target sink");
23 template <
typename... Sinks, std::enable_if_t<(
sizeof...(Sinks) <= N),
int> = 0>
24 explicit constexpr tee_sink(Sinks... sinks) noexcept : targets_{sinks...}, count_(
sizeof...(Sinks)) {}
32 [[nodiscard]]
sink as_sink() & noexcept RELOCO_LIFETIMEBOUND {
33 return sink{
this, [](
void *ctx, microfmt::string_view sv)
noexcept {
static_cast<tee_sink *
>(ctx)->
write(sv); }};
40 targets_[count_++] = s;
44 void put(
char c)
const noexcept {
45 for (
size_t i = 0; i < count_; ++i) {
50 void write(microfmt::string_view sv)
const noexcept {
51 for (
size_t i = 0; i < count_; ++i) {
52 targets_[i].write(sv);
56 [[nodiscard]]
constexpr size_t target_count() const noexcept {
return count_; }
59 microfmt::array<sink, N> targets_{};
64template <
typename... Sinks> [[nodiscard]]
constexpr auto make_tee(Sinks... sinks)
noexcept {
65 return tee_sink<
sizeof...(Sinks)>{sinks...};
Definition tee_sink.hpp:19
tee_sink(const tee_sink &)=delete
constexpr size_t target_count() const noexcept
Definition tee_sink.hpp:56
void write(microfmt::string_view sv) const noexcept
Definition tee_sink.hpp:50
constexpr tee_sink(Sinks... sinks) noexcept
Definition tee_sink.hpp:24
bool add_target(sink s) noexcept
Definition tee_sink.hpp:36
void put(char c) const noexcept
Definition tee_sink.hpp:44
tee_sink & operator=(const tee_sink &)=delete
tee_sink(tee_sink &&) noexcept=default
sink as_sink() &noexcept RELOCO_LIFETIMEBOUND
Definition tee_sink.hpp:32
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
constexpr auto make_tee(Sinks... sinks) noexcept
Definition tee_sink.hpp:64