Provides convenience methods for string formatting using C++20 <format>.
More...
#include <formatter.h>
|
| 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.
|
| |
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
std::array<char, 50> buffer;
Definition at line 118 of file formatter.h.
◆ format() [1/2]
template<typename... FormatArgs>
| static auto utility_module::formatter::format |
( |
const char * | formats, |
|
|
const FormatArgs &... | args ) -> std::string
|
|
inlinestatic |
◆ 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
-
| FormatArgs | Parameter pack of argument types. |
- Parameters
-
| formats | A wide format string (e.g. L"Count: {}, Value: {}"). |
| args | The 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
-
| OutputIt | The type of the output iterator (e.g. a back_inserter for a container). |
| FormatArgs | Parameter pack of argument types. |
- Parameters
-
| out | The output iterator where formatted text will be written. |
| formats | The narrow format string. |
| args | The 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
-
| OutputIt | The type of the output iterator (e.g. a back_inserter for a wstring). |
| FormatArgs | Parameter pack of argument types. |
- Parameters
-
| out | The output iterator where formatted text will be written. |
| formats | The wide format string. |
| args | The 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: