json
json copied to clipboard
Fix example code for json::json_pointer initialization
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/nlohmanndirectory, runmake amalgamateto create the single-header filessingle_include/nlohmann/json.hppandsingle_include/nlohmann/json_fwd.hpp. The whole process is described here.