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

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

Namespaces

 

Classes

struct  FString
 
struct  FormatToNResult
 
struct  FormatToResult
 

Typedefs

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

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...
 
template<typename... ArgsT>
std::string format (format_string< ArgsT... > fmt, const ArgsT &... args)
 Formats args into a newly allocated std::string. More...
 

Detailed Description

Minimal allocation-free {} placeholder formatter.

Details.

Typedef Documentation

◆ format_string

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

Function Documentation

◆ format()

template<typename... ArgsT>
std::string vlink::format::format ( format_string< ArgsT... >  fmt,
const ArgsT &...  args 
)
inline

Formats args into a newly allocated std::string.

Convenience wrapper over the iterator format_to; the only entry point that allocates. Hot paths should prefer format_to_n with a caller-owned buffer.

Template Parameters
ArgsTArgument types.
Parameters
fmtFormat string.
argsArguments to substitute.
Returns
Formatted result.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.