Skip to content

Add StringView template typename to basic_json #297

@dv1

Description

@dv1

Currently, basic_json expects one string type, which is used for everything - arguments, temporary strings, etc. This may be inefficient if data is available as some sort of a "string view". For example, if a C API offers a const char* value and a length integer, then it is possible to wrap these in a boost::string_ref instance. Since the JSON parser does not modify the source string, it would be possible to allow for specifying something like boost::string_ref as a "StringView" template typename, and std::string as a "String" type, which is then used internally.

The net gain is that a copy is avoided. In the example mentioned above, I have to create a temporary std::string and do a copy of the source string. With a StringView typename, I could avoid that copy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: please discussplease discuss the issue or vote for your favorite option

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions