Skip to content

Proposal: prepared statements  #618

Closed
@gabime

Description

@gabime

While #613 would be great, but will probably only supported for c++17.

Another approach would be to have kind of prepared templates (or prepared statements - a bit like in db, but fmt need not to store or manage the handle anywhere - the handle itself would contain all the needed info).

The user would pass a format string he expects to use a lot and get a handle to a "compiled" version of the format string:

// fmt returns a handle object that can be executed like this:
auto handle = fmt::prepare("My name is {}. I am {} years old."); 


// and then the user can make heavy use of it
auto result = handle->format(arg1, arg2);
// or maybe
auto result = fmt::format(handle, arg1, arg2);

The handle would contain an efficient representation of the format - list of actual formatters to use, their flags, and their offsets in the format string.
I am not sure if the result would be much faster for simple format strings, but complex format strings, it might give big performance boost.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions