VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
vlink::format Namespace Reference

Lightweight header-only {} placeholder formatter. More...

Namespaces

namespace  detail

Classes

struct  FString
 Compile-time format string wrapper that carries type information about arguments. More...
struct  FormatToNResult
 Result type for format_to_n, carrying the output pointer, written size and truncation flag. More...
struct  FormatToResult
 Result type for the fixed-array overload of format_to. More...

Typedefs

template<typename... T>
using format_string = typename FString<T...>::t
 Alias for FString used as the type of format-string parameters.

Functions

template<typename... ArgsT>
detail::FormatArgStore< char, detail::RemoveCvref< ArgsT >... > make_format_args (const ArgsT &... args)
 Creates a type-erased argument store from a variadic argument list.
template<typename... ArgsT>
FormatToNResult< char * > 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 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 > format_to (OutputItT &&out, format_string< ArgsT... > fmt, const ArgsT &... args)
 Formats arguments to an output iterator.

Detailed Description

Lightweight header-only {} placeholder formatter.

Typedef Documentation

◆ format_string

template<typename... T>
using vlink::format::format_string = typename FString<T...>::t

Alias for FString used as the type of format-string parameters.

format_string<ArgsT...> is the type of the format argument in format_to_n and format_to. Constructed implicitly from string literals.

Template Parameters
TExpected argument types (for documentation; not enforced at runtime).

Function Documentation

◆ format_to() [1/2]

template<size_t N, typename... ArgsT>
FormatToResult vlink::format::format_to ( char(&) out[N],
format_string< ArgsT... > fmt,
const ArgsT &... args )
inline

Formats arguments into a fixed-size char array.

The array size N is deduced automatically. Equivalent to format_to_n(out, N, fmt, args...).

Template Parameters
NArray size (deduced).
ArgsTArgument types.
Parameters
outDestination char array.
fmtFormat string.
argsFormat arguments.
Returns
FormatToResult with end pointer, total size and truncation flag.
Here is the call graph for this function:

◆ format_to() [2/2]

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 )
inline

Formats arguments to an output iterator.

Writes each character via *out++ = c. The iterator must model the OutputIterator concept (assignable and dereferenceable).

Template Parameters
OutputItTOutput iterator type.
ArgsTArgument types.
Parameters
outDestination output iterator.
fmtFormat string with {} placeholders.
argsFormat arguments.
Returns
The iterator one past the last written character.
Here is the call graph for this function:

◆ format_to_n()

template<typename... ArgsT>
FormatToNResult< char * > vlink::format::format_to_n ( char * out,
size_t n,
format_string< ArgsT... > fmt,
const ArgsT &... args )
inline

Formats arguments into a char* buffer, writing at most n characters.

Placeholders ({}) in fmt are replaced in order by the corresponding argument from args. If more characters would be produced than n, output is truncated and the returned truncated flag is set. The caller must null-terminate the output if needed.

Template Parameters
ArgsTArgument types (deduced).
Parameters
outDestination buffer. Must have capacity of at least n bytes.
nMaximum number of characters to write (not counting a null terminator).
fmtFormat string with {} placeholders.
argsFormat arguments.
Returns
FormatToNResult with the end pointer, total size and truncation flag.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_format_args()

template<typename... ArgsT>
detail::FormatArgStore< char, detail::RemoveCvref< ArgsT >... > vlink::format::make_format_args ( const ArgsT &... args)
inline

Creates a type-erased argument store from a variadic argument list.

Template Parameters
ArgsTArgument types.
Parameters
argsArguments to capture.
Returns
FormatArgStore containing the erased argument values.
Here is the caller graph for this function: