API Reference for fmt-display-cpp

Comprehensive documentation of fmt-display-cpp's core components and functions.

Display Trait

The fmt::Display trait is the core of fmt-display-cpp's customization capabilities:

fmt::Display
template<typename T>
struct fmt::Display {
    static std::string print(const T& value);
};

// Example specialization
template<>
struct fmt::Display<MyCustomType> {
    static std::string print(const MyCustomType& value) {
        // Custom implementation
        return fmt::format_string("MyCustomType(%s)", value.toString());
    }
};

Specialize this trait for your custom types to control how they are displayed in all fmt-display-cpp operations.

fmtout Methods

The fmt::fmtout class provides a stream-like interface for building formatted strings:

fmt::fmtout
class fmt::fmtout {
public:
    // Append a value to the internal buffer
    template<typename T>
    fmtout& operator<<(const T& value);

    // Get the formatted string
    std::string str() const;

    // Clear the internal buffer
    void clear();
};

Use fmtout when you need to build complex formatted strings with multiple components or styling changes.

PrintFormatter Methods

The fmt::PrintFormatter class allows for customized printing with user-defined separators and end-of-line characters:

fmt::PrintFormatter
class fmt::PrintFormatter {
public:
    // Constructor
    PrintFormatter(const std::string& sep = "", const std::string& end = "");

    // Print multiple arguments
    template<typename... Args>
    void print(const Args&... args);

    // Return formatted string without printing
    template<typename... Args>
    std::string sprint(const Args&... args);
};

Use PrintFormatter to create specialized formatting for various output needs, such as CSV generation or simple serialization.

ANSI Namespace Constants

The ansi namespace provides constants for text styling:

  • ansi::reset: Reset all styling
  • ansi::bold: Bold text
  • ansi::italic: Italic text
  • ansi::underline: Underlined text
  • ansi::red: Red text
  • ansi::green: Green text
  • ansi::blue: Blue text
  • ansi::yellow: Yellow text
  • ansi::magenta: Magenta text
  • ansi::cyan: Cyan text

Helper Functions

fmt-display-cpp provides several helper functions for common formatting tasks:

Helper Functions
namespace fmt {
    // Format a string with type-safe arguments
    template<typename... Args>
    std::string format_string(const std::string& format, Args... args);

    // Print without newline
    template<typename... Args>
    void print(const Args&... args);

    // Print with newline
    template<typename... Args>
    void println(const Args&... args);
}

These functions provide convenient ways to format strings and print output with or without newlines.