Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

formatter

(EXPERIMENTAL) An extension point to customize SQL formatting.

Synopsis

Defined in header <boost/mysql/format_sql.hpp>

template<
    class T>
struct formatter
Description

This type can be specialized for custom types to make them formattable. This makes them satisfy the Formattable concept, and thus usable in format_sql and similar functions.

A formatter specialization for a type T should have the following form:

template <>
struct formatter<T>
{
    const char * parse( const char * begin, const char * end); // parse format specs
    void format( const T& value, format_context_base& ctx) const ; // perform the actual formatting
};

When a value with a custom formatter is formatted (using format_sql or a similar function), the library performs the following actions:

Don't specialize formatter for built-in types, like int, std::string or optionals (formally, any type satisfying WritableField), as the specializations will be ignored.


PrevUpHomeNext