|
VLink 2.0.0
A high-performance communication middleware
|
Lightweight header-only {} placeholder formatter with no dynamic allocation.
More...
#include <cstddef>#include <cstdint>#include <cstdio>#include <cstring>#include <string>#include <string_view>#include <type_traits>#include <utility>#include "./macros.h"Go to the source code of this file.
Namespaces | |
| namespace | vlink |
| namespace | vlink::format |
Lightweight header-only {} placeholder formatter. | |
| namespace | vlink::format::detail |
Typedefs | |
| template<typename T> | |
| using | vlink::format::detail::RemoveCvref = typename std::remove_cv_t<std::remove_reference_t<T>> |
| using | vlink::format::detail::FormatArgs = BasicFormatArgs<char> |
| template<typename... T> | |
| using | vlink::format::format_string = typename FString<T...>::t |
Alias for FString used as the type of format-string parameters. | |
Functions | |
| template<typename UIntT> | |
| int | vlink::format::detail::count_digits (UIntT n) |
| template<typename CharT, typename UIntT> | |
| CharT * | vlink::format::detail::write_int_digits (CharT *buf, UIntT value, int num_digits) |
| template<typename... ArgsT> | |
| detail::FormatArgStore< char, detail::RemoveCvref< ArgsT >... > | vlink::format::make_format_args (const ArgsT &... args) |
| Creates a type-erased argument store from a variadic argument list. | |
| template<typename... ArgsT> | |
| FormatToNResult< char * > | vlink::format::format_to_n (char *out, size_t n, format_string< ArgsT... > fmt, const ArgsT &... args) |
Formats arguments into a char* buffer, writing at most n characters. | |
| template<size_t N, typename... ArgsT> | |
| FormatToResult | vlink::format::format_to (char(&out)[N], format_string< ArgsT... > fmt, const ArgsT &... args) |
| Formats arguments into a fixed-size char array. | |
| 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 arguments to an output iterator. | |
Variables | |
| template<typename T> | |
| constexpr bool | vlink::format::detail::kIsOutputIterator = IsOutputIteratorImpl<T>::value |
Lightweight header-only {} placeholder formatter with no dynamic allocation.
This namespace provides a minimal subset of std::format-compatible formatting for use inside the VLink logger hot path where <format> may be unavailable (C++17) or too heavyweight. All formatting writes through a stack-allocated writer or a user-supplied output iterator and never touches the heap.
Supported argument types:
| C++ type | Format token | Example output |
|---|---|---|
| int / short / signed char | {} | 42 |
| unsigned / unsigned short / ... | {} | 42 |
| long / long long | {} | 123456789 |
| unsigned long / long long | {} | 123456789 |
| bool | {} | true / false |
| char | {} | A |
| float / double | {} | 3.14 |
| const char* / char* | {} | hello |
| std::string / std::string_view | {} | hello |
| T* (any pointer) | {} | 0x7ffe1234 |
| enum (any) | {} | underlying int |
Placeholder syntax:
{} – consume arguments in order.{0}, {1}, ... – explicit positional indexing.{{ / }} – literal brace.Public API:
format_to_n(out, n, fmt, args...) – writes at most n chars into a char* buffer.format_to(out[N], fmt, args...) – writes into a fixed array.format_to(iterator, fmt, args...) – writes to an output iterator.snprintf with "%g". There is no precision specifier in the placeholder syntax.static_assert at compile time.format_to_n results set the truncated flag in the returned struct.