json icon indicating copy to clipboard operation
json copied to clipboard

Fix example code for json::json_pointer initialization

Open kfwu1999 opened this issue 1 year ago • 0 comments

Description

In #4453, the compilation error of json::json_pointer p = "/nested/one"; is due to the implicit conversion, as the constructor for json_pointer is marked explicit (see following source code).

https://github.com/nlohmann/json/blob/b36f4c477c40356a0ae1204b567cca3c2a57d201/include/nlohmann/detail/json_pointer.hpp#L62-L64

Removing the explicit can allows to compile and pass the test, but i think it it might violate the design intentions.

Modification

Changed the example code in the documentation (https://json.nlohmann.me/features/json_pointer/#json-pointer-creation) from copy initialization to direct initialization.

Before

json::json_pointer p = "/nested/one";

After

json::json_pointer p("/nested/one");

Pull request checklist

Read the Contribution Guidelines for detailed information.

  • [x] Changes are described in the pull request, or an existing issue is referenced.
  • [x] The test suite compiles and runs without error.
  • [x] Code coverage is 100%. Test cases can be added by editing the test suite.
  • [x] The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header files single_include/nlohmann/json.hpp and single_include/nlohmann/json_fwd.hpp. The whole process is described here.

kfwu1999 avatar Sep 25 '24 11:09 kfwu1999