Container System 0.1.0
High-performance C++20 type-safe container framework with SIMD-accelerated serialization
Loading...
Searching...
No Matches
utility_module::formatter Class Reference

Simple formatter wrapper around std::format. More...

#include <formatter.h>

Collaboration diagram for utility_module::formatter:
Collaboration graph

Static Public Member Functions

template<typename... Args>
static std::string format (const std::string &format_str, Args &&... args)
 
template<typename OutputIt , typename... Args>
static void format_to (OutputIt out, const std::string &format_str, Args &&... args)
 
static std::string format (const std::string &format_str)
 

Static Private Member Functions

template<typename T >
static void replace_next (std::string &str, T &&value)
 

Detailed Description

Simple formatter wrapper around std::format.

Uses std::vformat when full C++20 <format> support is available (GCC 13+, MSVC 19.29+). Falls back to ostringstream-based placeholder substitution on compilers with incomplete <format> (e.g. Apple Clang).

Definition at line 29 of file formatter.h.

Member Function Documentation

◆ format() [1/2]

static std::string utility_module::formatter::format ( const std::string & format_str)
inlinestatic

Definition at line 69 of file formatter.h.

69 {
70 return format_str;
71 }

◆ format() [2/2]

template<typename... Args>
static std::string utility_module::formatter::format ( const std::string & format_str,
Args &&... args )
inlinestatic

Definition at line 55 of file formatter.h.

55 {
56 std::string result = format_str;
57 (replace_next(result, std::forward<Args>(args)), ...);
58 return result;
59 }
static void replace_next(std::string &str, T &&value)
Definition formatter.h:76

References replace_next().

Referenced by format_to().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format_to()

template<typename OutputIt , typename... Args>
static void utility_module::formatter::format_to ( OutputIt out,
const std::string & format_str,
Args &&... args )
inlinestatic

Definition at line 62 of file formatter.h.

62 {
63 std::string result = format(format_str, std::forward<Args>(args)...);
64 std::copy(result.begin(), result.end(), out);
65 }
static std::string format(const std::string &format_str, Args &&... args)
Definition formatter.h:55

References format().

Here is the call graph for this function:

◆ replace_next()

template<typename T >
static void utility_module::formatter::replace_next ( std::string & str,
T && value )
inlinestaticprivate

Definition at line 76 of file formatter.h.

76 {
77 auto pos = str.find("{}");
78 if (pos == std::string::npos) return;
79
80 std::ostringstream oss;
81 oss << std::forward<T>(value);
82 str.replace(pos, 2, oss.str());
83 }

Referenced by format().

Here is the caller graph for this function:

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