Skip to content

json constructor does not support std::optional #2214

Closed

Description

@gzliudan

I'm using clang 9.0 which support C++17, but below codes can't pass compile when I use nlohmann::json:

std::optional<int> value;
auto json = nlohmann::json{{"opt", value}};

instead, I have to use below codes:
if (value) {
    json = nlohmann::json{{"opt", *value}};
} else {
    json = nlohmann::json{{"opt", nullptr}};
}

Activity

  1. dota17 commented on Jun 24, 2020

    @dota17
    Contributor

    Please See #1749 .
    There is a PR #2117 , but it didn't merge into develop because there are some problems.

  2. nlohmann commented on Jun 24, 2020

    @nlohmann
    Owner

    Duplicate of #1749.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugsolution: duplicatethe issue is a duplicate; refer to the linked issue instead

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions