Skip to content

string_view and constexpr-able objects #9

Open
@sraboy

Description

@sraboy

Any chance of string_view support?

And, though it would be a ton of work on your part, I'd love to be able to (somehow) get a constexpr std::string_view out of a json::object. I prefer using json::object over plain string literals but std::string does malloc after (I think) 15 bytes on MSVC so there's occasionally a lot of unnecessary overhead.

For example, I'm communicating with a server with JSON and I have something like this:

std::string json_get_thing(std::string const& guid, 
                           std::string const& data, 
                           int const an_int) {
        json::object to_send = {
            { "command", "PUT" },
            { "guid", guid },
            { "data", data },
            { "an_int", an_int },
        };

        return json::stringify(to_send);
    }

At least some of the json::values (e.g., command) are just string literals and, at times, all three function params are known at compile time. I'd like to be able to do this:

    constexpr std::string_view json_get_thing(std::string_view guid,
                                              std::string_view data,
                                              int const an_int) {
        return json::string_viewify( {
            { "command", "PUT" },
            { "guid", guid },
            { "data", data },
            { "an_int", an_int },
        });
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions