|
| VLINK_EXPORT size_t | vlink::format::detail::format_uint_to (char *buf, unsigned value) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_int_to (char *buf, int value) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_ulong_long_to (char *buf, unsigned long long value) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_long_long_to (char *buf, long long value) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_pointer_to (char *buf, const void *ptr) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_float_to (char *buf, size_t buflen, float value) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_double_to (char *buf, size_t buflen, double value) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_long_double_to (char *buf, size_t buflen, long double value) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_double_spec_to (char *buf, size_t buflen, double value, char type, int precision, bool alt) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_long_double_spec_to (char *buf, size_t buflen, long double value, char type, int precision, bool alt) noexcept |
| |
| VLINK_EXPORT const char * | vlink::format::detail::parse_spec_ref (const char *p, const char *end, int &ref) noexcept |
| |
| VLINK_EXPORT const char * | vlink::format::detail::parse_format_spec (const char *p, const char *end, FormatSpec &spec) noexcept |
| |
| VLINK_EXPORT size_t | vlink::format::detail::format_base_digits_to (char(&buf)[64], unsigned long long value, unsigned base_bits, bool upper) noexcept |
| |
| template<typename... ArgsT> |
| detail::FormatArgStore< char, detail::RemoveCvref< ArgsT >... > | vlink::format::make_format_args (const ArgsT &... args) |
| | Public API. More...
|
| |
| template<typename... ArgsT> |
| FormatToNResult< char * > | vlink::format::format_to_n (char *out, size_t n, format_string< ArgsT... > fmt, const ArgsT &... args) |
| | Formats args into out, writing at most n characters. More...
|
| |
| template<size_t NumT, typename... ArgsT> |
| FormatToResult | vlink::format::format_to (char(&out)[NumT], format_string< ArgsT... > fmt, const ArgsT &... args) |
| | Formats args into a fixed-size character array; equivalent to format_to_n. More...
|
| |
| template<typename OutputItT , typename... ArgsT, std::enable_if_t< detail::kIsOutputIterator< detail::RemoveCvref< OutputItT >> &&!std::is_array_v< std::remove_reference_t< OutputItT >>, int > = 0> |
| detail::RemoveCvref< OutputItT > | vlink::format::format_to (OutputItT &&out, format_string< ArgsT... > fmt, const ArgsT &... args) |
| | Formats args through an output iterator. More...
|
| |
| template<typename... ArgsT> |
| std::string | vlink::format::format (format_string< ArgsT... > fmt, const ArgsT &... args) |
| | Formats args into a newly allocated std::string. More...
|
| |
| template<typename UIntT > |
| int | vlink::format::detail::count_digits (UIntT n) noexcept |
| |
| template<typename UIntT > |
| void | vlink::format::detail::write_int_digits (char *buf, UIntT value, int num_digits) noexcept |
| |
Minimal heap-free {} placeholder formatter for the logger hot path.
VLink targets C++17 first; std::format is unavailable on that baseline and far heavier on older standards. This header provides a focused subset of std::format-style formatting that writes through a stack-allocated buffer or a user-supplied output iterator, never allocates, and dispatches via a compile-time type tag rather than a virtual call chain.
- Supported argument types
| C++ type | Example output |
all integral types incl. char and bool | 42 / A / true |
float / double / long double | 3.14 |
const char* / std::string / std::string_view | hello |
T* (any pointer) and nullptr | 0x7ffe1234 / 0x0 |
enum | underlying integer |
any type with an ADL format_as(T) | mapped result |
- Placeholder syntax
| Token | Meaning |
{} | Consume the next argument in order |
{0}, {1}, ... | Explicit positional index |
{:spec}, {0:spec} | Apply a std::format-style format spec |
{{ / }} | Literal opening / closing brace |
- Format specification
The std::format grammar: [[fill]align][sign][#][0][width][.precision][type]
- fill + align: any byte except braces before
< (left), > (right), ^ (center).
- sign:
+ / - / space for arithmetic presentations.
#: 0b / 0B / 0 / 0x / 0X prefix; floats keep the decimal point and g / G keep trailing zeros.
0: zero padding after sign/prefix; ignored with an explicit align.
- width / precision: literal digits, or dynamic
{} / {n} consuming an integral argument; precision also truncates strings.
- type:
b B c d o x X integral; a A e E f F g G floating; s string/bool; ? escaped debug string/char; p pointer.
- Public API
| Function | Output target | Allocates |
format_to_n(out, n, fmt, ...) | char* buffer with cap n | no |
format_to(out[N], fmt, ...) | Fixed-size array | no |
format_to(it, fmt, ...) | Output iterator | no |
format(fmt, ...) | Returned std::string | yes |
- Example
char buf[128];
buf[result.size] = '\0';
- Note
- Deviations from std::format: locale (
L) is not supported, the fill byte is single-byte, and invalid or inapplicable spec fields are ignored instead of throwing, so formatting never fails at runtime. A dynamic width/precision referencing a missing, non-integral or negative argument degrades to "not specified". Width and precision count bytes, so multi-byte UTF-8 sequences may be split by a string precision. Floating precision is clamped to 340 digits. A c presentation outside the char range and a c presentation of bool fall back to the decimal form. Without a spec (and for {:#} without type and precision), floating values use the "%g" 6 significant digit representation. Platforms without floating-point std::to_chars format floats through snprintf with printf semantics, including the a representation. The ? presentation escapes ASCII control bytes, quotes and backslashes; string bytes at or above 0x80 pass through unescaped while a lone char code unit above 0x7F is escaped as \x{..}. Unsupported argument types trigger a compile-time static_assert.
-
The allocating entry point shares its name with this namespace; call it fully qualified as
vlink::format::format(...). vlink::format(...) resolves to the namespace and does not compile.
-
Custom types opt in by defining
format_as(const T&) in the namespace of T, returning a directly formattable value; specs then apply to the mapped result. Class-type results must be returned by reference or as std::string_view.