Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
utility_module::formatter Class Reference

Provides convenience methods for string formatting using C++20 <format>. More...

#include <formatter.h>

Collaboration diagram for utility_module::formatter:
Collaboration graph

Static Public Member Functions

template<typename... FormatArgs>
static auto format (const char *formats, const FormatArgs &... args) -> std::string
 Formats a narrow-character string with the given arguments.
 
template<typename... FormatArgs>
static auto format (const wchar_t *formats, const FormatArgs &... args) -> std::wstring
 Formats a wide-character string with the given arguments.
 
template<typename OutputIt , typename... FormatArgs>
static auto format_to (OutputIt out, const char *formats, const FormatArgs &... args) -> OutputIt
 Formats a narrow-character string directly to an output iterator.
 
template<typename OutputIt , typename... FormatArgs>
static auto format_to (OutputIt out, const wchar_t *formats, const FormatArgs &... args) -> OutputIt
 Formats a wide-character string directly to an output iterator.
 

Detailed Description

Provides convenience methods for string formatting using C++20 <format>.

The formatter class offers static functions to format strings (both narrow and wide) into a std::string / std::wstring, or directly to an output iterator.

Example

// Basic usage:
std::string result = formatter::format("Hello, {}", "World");
// Writing directly to a buffer:
std::array<char, 50> buffer;
auto it = formatter::format_to(buffer.begin(), "Number: {}", 42);
// 'it' now points to the end of the written text
static auto format_to(OutputIt out, const char *formats, const FormatArgs &... args) -> OutputIt
Formats a narrow-character string directly to an output iterator.
Definition formatter.h:162
static auto format(const char *formats, const FormatArgs &... args) -> std::string
Formats a narrow-character string with the given arguments.
Definition formatter.h:132

Definition at line 118 of file formatter.h.

Member Function Documentation

◆ format() [1/2]

template<typename... FormatArgs>
static auto utility_module::formatter::format ( const char * formats,
const FormatArgs &... args ) -> std::string
inlinestatic

Formats a narrow-character string with the given arguments.

Template Parameters
FormatArgsParameter pack of argument types.
Parameters
formatsA format string (e.g. "Name: {}, Age: {}").
argsThe arguments to substitute into formats.
Returns
A std::string containing the formatted result.

Definition at line 129 of file formatter.h.

130 {
131 return std::vformat(formats, std::make_format_args(args...));
132 }

Referenced by kcenon::thread::autoscaler::make_decision(), kcenon::thread::backpressure_job_queue::to_string(), kcenon::thread::job_queue::to_string(), kcenon::thread::policy_queue_adapter< SyncPolicy, BoundPolicy, OverflowPolicy >::to_string(), and kcenon::thread::thread_base::to_string().

Here is the caller graph for this function:

◆ format() [2/2]

template<typename... FormatArgs>
static auto utility_module::formatter::format ( const wchar_t * formats,
const FormatArgs &... args ) -> std::wstring
inlinestatic

Formats a wide-character string with the given arguments.

Template Parameters
FormatArgsParameter pack of argument types.
Parameters
formatsA wide format string (e.g. L"Count: {}, Value: {}").
argsThe arguments to substitute into formats.
Returns
A std::wstring containing the formatted result.

Definition at line 142 of file formatter.h.

143 {
144 return std::vformat(formats, std::make_wformat_args(args...));
145 }

◆ format_to() [1/2]

template<typename OutputIt , typename... FormatArgs>
static auto utility_module::formatter::format_to ( OutputIt out,
const char * formats,
const FormatArgs &... args ) -> OutputIt
inlinestatic

Formats a narrow-character string directly to an output iterator.

Template Parameters
OutputItThe type of the output iterator (e.g. a back_inserter for a container).
FormatArgsParameter pack of argument types.
Parameters
outThe output iterator where formatted text will be written.
formatsThe narrow format string.
argsThe arguments to substitute into formats.
Returns
The output iterator advanced to the end of the written text.

This method is useful when writing to a buffer, a container, or custom iterators.

Definition at line 159 of file formatter.h.

161 {
162 return std::vformat_to(out, formats, std::make_format_args(args...));
163 }

◆ format_to() [2/2]

template<typename OutputIt , typename... FormatArgs>
static auto utility_module::formatter::format_to ( OutputIt out,
const wchar_t * formats,
const FormatArgs &... args ) -> OutputIt
inlinestatic

Formats a wide-character string directly to an output iterator.

Template Parameters
OutputItThe type of the output iterator (e.g. a back_inserter for a wstring).
FormatArgsParameter pack of argument types.
Parameters
outThe output iterator where formatted text will be written.
formatsThe wide format string.
argsThe arguments to substitute into formats.
Returns
The output iterator advanced to the end of the written text.

Definition at line 175 of file formatter.h.

177 {
178 return std::vformat_to(out, formats, std::make_wformat_args(args...));
179 }

The documentation for this class was generated from the following file: