microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
boost_containers.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Jarosław Pelczar <jarek@jpelczar.com>
2//
3// SPDX-License-Identifier: BSD-2-Clause
4
5#pragma once
6
9#include "../microfmt.hpp"
10#include "ranges.hpp"
11#include <boost/container/small_vector.hpp>
12#include <boost/container/static_vector.hpp>
13
14namespace microfmt {
15namespace detail {
16
17template <typename Container> struct RELOCO_POINTER boost_sequence_formatter {
18 microfmt::string_view element_spec{};
19
20 constexpr void parse(format_parse_context &ctx) noexcept { element_spec = ctx.spec(); }
21
22 void format(const Container &container, const sink &out) const noexcept {
23 out.put('[');
24 auto joined = microfmt::join(container);
25 formatter<decltype(joined)> joined_formatter;
26 format_parse_context element_context(element_spec);
27 joined_formatter.parse(element_context);
28 joined_formatter.format(joined, out);
29 out.put(']');
30 }
31};
32
33} // namespace detail
34
35template <typename T, std::size_t Capacity, typename Options>
36struct formatter<boost::container::static_vector<T, Capacity, Options>>
37 : detail::boost_sequence_formatter<boost::container::static_vector<T, Capacity, Options>> {};
38
39template <typename T, std::size_t N, typename Allocator, typename Options>
40struct formatter<boost::container::small_vector<T, N, Allocator, Options>>
41 : detail::boost_sequence_formatter<boost::container::small_vector<T, N, Allocator, Options>> {};
42
43} // namespace microfmt
Definition microfmt.hpp:881
Definition assert.hpp:19
reloco::sink sink
Type-erased, zero-allocation output sink.
Definition microfmt.hpp:46
constexpr joined_span_view< T > join(span< const T > items, microfmt::string_view delim=", ") noexcept
Definition format_helpers.hpp:239
Range and iterator-pair joining formatting views.
Definition boost_containers.hpp:17
void format(const Container &container, const sink &out) const noexcept
Definition boost_containers.hpp:22
constexpr void parse(format_parse_context &ctx) noexcept
Definition boost_containers.hpp:20
Definition microfmt.hpp:985