Skip to content

Add support for fixed sized buffers #105

Closed
@mateofio

Description

@mateofio

This library looks very promising. One thing that's missing is efficient snprintf() like functionality which can print directly to a fixed size buffer with truncation but without any memory allocations.

I would suggest an interface like this:

StringRef format(ArrayRef<char> buffer, StringRef fmt, ArgList args);

In this example, ArrayRef would be a simplified version of array_view which is proposed for C++17. You don't need all of the multi-dimensional and striding support, just a generic adapter for any array type container.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3851.pdf

The returned StringRef references a sub-array of buffer that was filled in by the formatting.

Usage example:

char path_buf[4096];
auto path = format(path_buf, "{}/{}", dir, filename);

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