Skip to content

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

Closed

Description

@nlohmann

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

Activity

  1. added this to the Release 3.0.0 milestone on Mar 1, 2017
  2. self-assigned this
    on Mar 1, 2017
  3. nlohmann commented on Mar 1, 2017

    @nlohmann
    OwnerAuthor

    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
  4. gregmarr commented on Mar 1, 2017

    @gregmarr
    Contributor

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

  5. nlohmann commented on Mar 1, 2017

    @nlohmann
    OwnerAuthor

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

  6. added a commit that references this issue on Jun 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions