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

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

#include <formatter.h>

Collaboration diagram for kcenon::thread::utils::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
A template class representing either a value or an error.
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
Examples
job_cancellation_example.cpp, logger_sample.cpp, multi_process_monitoring_integration.cpp, thread_pool_sample.cpp, typed_thread_pool_sample.cpp, and typed_thread_pool_sample_2.cpp.

Definition at line 121 of file formatter.h.

Member Function Documentation

◆ format() [1/2]

template<typename... FormatArgs>
static auto kcenon::thread::utils::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 132 of file formatter.h.

133 {
134 return std::vformat(formats, std::make_format_args(args...));
135 }

Referenced by create_default(), create_default(), demo_basic_cancellation(), demo_immediate_vs_graceful(), demo_non_cooperative_job(), demo_pool_level_cancellation(), kcenon::thread::thread_worker::do_work(), initialize_logger(), main(), main(), kcenon::thread::thread_worker::on_stop_requested(), kcenon::thread::thread_pool::remove_workers_internal(), kcenon::thread::thread_pool::stop(), store_job(), store_job(), and kcenon::thread::job::to_string().

Here is the caller graph for this function:

◆ format() [2/2]

template<typename... FormatArgs>
static auto kcenon::thread::utils::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 145 of file formatter.h.

146 {
147 return std::vformat(formats, std::make_wformat_args(args...));
148 }

◆ format_to() [1/2]

template<typename OutputIt , typename... FormatArgs>
static auto kcenon::thread::utils::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 162 of file formatter.h.

164 {
165 return std::vformat_to(out, formats, std::make_format_args(args...));
166 }

Referenced by kcenon::thread::thread_pool::to_string().

Here is the caller graph for this function:

◆ format_to() [2/2]

template<typename OutputIt , typename... FormatArgs>
static auto kcenon::thread::utils::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 178 of file formatter.h.

180 {
181 return std::vformat_to(out, formats, std::make_wformat_args(args...));
182 }

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