Skip to content

Add support for json::string to std::string_view conversion #538

@elegracer

Description

@elegracer

When I'm using Boost.JSON along with Boost.Beast, it's common to parse a json frame from a remote http/websocket server and do some processing with it.

A typical scenario is, I need to pass a json::string to a function where a std::string_view is expected.

I can use standalone Boost.JSON with macro BOOST_JSON_STANDALONE to replace boost::string_view with std::string_view. But since I also need Boost.Beast, mixing Boost and standalone Boost.JSON would result in a lot of "macro redefinition" error.

So now I have to tediously do the conversion like this everytime

void process_sv(std::string_view sv);

auto j_str = j_v.as_string();
auto j_sv = std::string_view(j_str.data(), j_str.size());

process_sv(j_sv);

It would make it much more convenient if a direct conversion from json::string to std::string_view is available.

Thank you!

Metadata

Metadata

Assignees

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