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

Remove deprecated constructor basic_json(std::istream&) #480

Closed
nlohmann opened this issue Mar 1, 2017 · 3 comments
Closed

Remove deprecated constructor basic_json(std::istream&) #480

nlohmann opened this issue Mar 1, 2017 · 3 comments
Assignees
Milestone

Comments

@nlohmann
Copy link
Owner

nlohmann commented Mar 1, 2017

Function

explicit basic_json(std::istream& i, const parser_callback_t cb = nullptr)

has been deprecated since version 2.0.0 (June 24, 2016) to unify the interface of the library. Deprecation warnings were produced with GCC, Clang, and MSVC.

To create objects from an input stream, there remain the following possibilities:

  • with callback:
    • parse(std::istream& i, const parser_callback_t cb = nullptr)
  • without callback
    • std::istream& operator<<(basic_json& j, std::istream& i)
    • std::istream& operator>>(std::istream& i, basic_json& j)

That is, code without callback cb

json j(i);

must be replaced by either

// alternative 1
json j = json::parse(i);

// alternative 2
json j;
j << i;

// alternative 3
json j;
i >> j;

Code with a callback function cb

json j(i, cb);

must be replaced by

json j = json::parse(i, cb);
@nlohmann nlohmann added this to the Release 3.0.0 milestone Mar 1, 2017
@nlohmann nlohmann self-assigned this Mar 1, 2017
@nlohmann
Copy link
Owner Author

nlohmann commented Mar 1, 2017

As there is no other deprecated code, here is the macro for reference:

// allow for portable deprecation warnings
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    #define JSON_DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
    #define JSON_DEPRECATED __declspec(deprecated)
#else
    #define JSON_DEPRECATED
#endif

nlohmann added a commit that referenced this issue Mar 1, 2017
The constructor basic_json(std::istream&, const parser_callback_t) has
been deprecated since version 2.0.0. This commit removes it together
with its code example, deprecation macro, and test cases. The code now
also compiles with -W-deprecated-declarations.
@gregmarr
Copy link
Contributor

gregmarr commented Mar 1, 2017

Have you looked at using C++14's [[deprecated]] if C++14 is enabled?

@nlohmann
Copy link
Owner Author

nlohmann commented Mar 1, 2017

@gregmarr No, but this is a good idea for the future.

@nlohmann nlohmann closed this as completed Mar 2, 2017
tony added a commit to tony/sdl2-playproject that referenced this issue Jun 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants