Skip to content

Allow for forward declaring nlohmann::json #381

Closed

Description

@marton78

To avoid including json.hpp in header files, I would like to forward declare nlohmann::json as follows:

namespace nlohmann { struct json; }

struct my_stuff
{
    int some_member;
    nlohmann::json encode() const;
    void decode(nlohmann::json const&);
};

However, this doesn't work, since nlohmann::json is a typedef. If you just derived it from basic_json<>, it would work:

struct json : basic_json<>
{
    using basic_json<>::basic_json;
};

What do you think?

Activity

  1. gregmarr commented on Dec 6, 2016

    @gregmarr
    Contributor

    See discussions in #314

  2. nlohmann commented on Dec 6, 2016

    @nlohmann
    Owner

    @marton78 Please add this idea to #314.

  3. gregmarr commented on Dec 6, 2016

    @gregmarr
    Contributor

    @nlohmann @marton78 That idea was already mentioned in #314.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions