ORIGINAL
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
std::formatter< T > Struct Template Reference

std::formatter specialization for printable types More...

#include <printable.h>

Collaboration diagram for std::formatter< T >:
Collaboration graph

Static Public Member Functions

static constexpr auto parse (format_parse_context &ctx)
 Parses the format specification for printable types.
 
static auto format (const T &p, format_context &ctx)
 Formats the printable object using its string conversion.
 

Detailed Description

template<typename T>
requires original::ExtendsOf<original::printable, T>
struct std::formatter< T >

std::formatter specialization for printable types

Template Parameters
TType derived from printable

Enables use of printable-derived types with C++20 std::format. Uses the object's string conversion operators for consistent formatting across all output mechanisms.

Example usage:

MyClass obj;
auto s1 = std::format("Object: {}", obj); // Basic formatting
auto s2 = std::format("Object: {:<20}", obj); // With format spec
auto s3 = std::format("Object: {:.10}", obj); // With precision
Note
The formatter delegates to std::string formatter after converting the printable object to string.

Member Function Documentation

◆ format()

template<typename T >
auto std::formatter< T >::format ( const T &  p,
format_context &  ctx 
)
static

Formats the printable object using its string conversion.

Parameters
pPrintable object to format
ctxFormat context
Returns
Iterator past the formatted output

Converts the printable object to string using its explicit conversion operator, then delegates to the std::string formatter for actual formatting.

◆ parse()

template<typename T >
constexpr auto std::formatter< T >::parse ( format_parse_context &  ctx)
staticconstexpr

Parses the format specification for printable types.

Parameters
ctxFormat parse context
Returns
Iterator past the parsed format specification

Currently accepts any format specification and delegates parsing to the underlying string formatter.


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