Skip to content

Feature request: Implicit conversion to bool #951

@wolframroesler

Description

@wolframroesler

What's the general opinion about allowing json objects in a boolean context? For example:

json j = nullptr;
if (!j) {
    std::cout << "The object is null\n";
}

if (j) should be the same as if (!j.is_null()), and if (!j) should be the same as if (j.is_null()).

In the present version, the code above throws an exception ("[json.exception.type_error.302] type must be boolean, but is object").

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: please discussplease discuss the issue or vote for your favorite option

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions