VLink  2.0.0
A high-performance communication middleware
vlink::format Namespace Reference

Minimal allocation-free {} placeholder formatter. More...

Namespaces

 

Classes

struct  FString
 Compile-time format-string wrapper carrying the expected argument list. More...
 
struct  FormatToNResult
 Return type of format_to_n; carries the end iterator, total size and truncation flag. More...
 
struct  FormatToResult
 Return type of the fixed-array format_to overload. More...
 

Typedefs

template<typename... ArgsT>
using format_string = typename FString< ArgsT... >::t
 Convenience alias used as the formal type of format-string parameters. More...
 

Functions

template<typename... ArgsT>
detail::FormatArgStore< char, detail::RemoveCvref< ArgsT >... > make_format_args (const ArgsT &... args)
 Public API. More...
 
template<typename... ArgsT>
FormatToNResult< char * > 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 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 > format_to (OutputItT &&out, format_string< ArgsT... > fmt, const ArgsT &... args)
 Formats args through an output iterator. More...
 

Detailed Description

Minimal allocation-free {} placeholder formatter.

Typedef Documentation

◆ format_string

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

Convenience alias used as the formal type of format-string parameters.

Template Parameters
ArgsTExpected argument types.

Function Documentation

◆ format_to() [1/2]

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

Formats args into a fixed-size character array; equivalent to format_to_n.

Template Parameters
NumTArray size (deduced).
ArgsTArgument types.
Parameters
outDestination array.
fmtFormat string.
argsArguments to substitute.
Returns
FormatToResult describing the end pointer, total size and truncation flag.

◆ 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 args through an output iterator.

Writes each character via *out++ = c. The iterator must satisfy the OutputIterator concept; arrays are explicitly excluded so the fixed-array overload wins overload resolution.

Template Parameters
OutputItTOutput iterator type.
ArgsTArgument types.
Parameters
outDestination iterator.
fmtFormat string.
argsArguments to substitute.
Returns
Iterator one past the last written character.

◆ 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 args into out, writing at most n characters.

Placeholders in fmt are substituted with args in order. When the produced text would exceed n the output is truncated and truncated is set to true. The caller is responsible for null termination if needed.

Template Parameters
ArgsTArgument types (deduced).
Parameters
outDestination buffer with capacity of at least n bytes.
nMaximum characters to write, not counting a null terminator.
fmtFormat string with {} placeholders.
argsArguments to substitute.
Returns
FormatToNResult describing the end iterator, total size and truncation flag.
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

Public API.

Builds a type-erased argument store from a parameter pack.

Template Parameters
ArgsTArgument types.
Parameters
argsArgument values.
Returns
Argument store usable by the format engine.