json icon indicating copy to clipboard operation
json copied to clipboard

json::string convert to std::string

Open vinniefalco opened this issue 3 years ago • 4 comments

Might be nice to have string::to_std_string although this means including <string>.

vinniefalco avatar Sep 22 '20 18:09 vinniefalco

  1. core/detail/string_view.hpp includes <string> so, not including it in JSON is moot.
  2. std::string s = json::string_view(json::string()); works. And with C++17 auto s = std::string(json::string()); also works. Is this good enough?

grisumbras avatar May 23 '22 18:05 grisumbras

Given

json::string js;

My intuition tells me that users want the expression js.to_string() (alternatively: js.to_std_string()) to return a std::string. This clearly expresses intent and can be searched. But I could be convinced otherwise. What is typical practice here?

vinniefalco avatar May 24 '22 00:05 vinniefalco

QString has toStdString, but I don't think Qt is the best example of model C++ API. I'm personally perfectly Ok with a conversion (even though it's a bit obscure in C++11 mode). So, let's keep the issue for now and see if users actually ask for a dedicated conversion function.

grisumbras avatar May 24 '22 07:05 grisumbras

I would prefer if users simply worked with the native json::string since that is the most efficient. Making it easy to convert to std::string only encourages inefficiency.

vinniefalco avatar May 24 '22 13:05 vinniefalco

Still no issues about this. I'm inclined to close this.

grisumbras avatar Apr 08 '24 14:04 grisumbras