Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix example code for json::json_pointer initialization #4468

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

kfwu1999
Copy link

@kfwu1999 kfwu1999 commented Sep 25, 2024

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).

explicit json_pointer(const string_t& s = "")
: reference_tokens(split(s))
{}

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.

  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite.
  • 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.

Changed the example code in the documentation from copy initialization
to direct initialization for `json::json_pointer`.
This prevents compilation errors caused by the constructor being explicit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant