Boost logo

Boost :

From: Vinnie Falco (vinnie.falco_at_[hidden])
Date: 2020-09-10 17:06:34

On Thu, Sep 10, 2020 at 10:01 AM Edward Diener via Boost
<boost_at_[hidden]> wrote:
> Did I miss something or did std::optional ( or boost::optional ) go away
> as a means of saying that some value does not exist ? The nullptr is for
> a null pointer. Using it otherwise seems wrong, even if the value is the
> same size of a nullptr.

"null" in JSON does not mean "value does not exist." It means... well,
it is a null. Some people use the word monostate, which I find
pretentious. optional, std or otherwise, has nothing to do with this.
A JSON variant container needs a way to have a null assigned to it,
just like all the other types (integers, floating point). Example:

    json::value jv;
    jv = 1; // assign an integer
    assert( jv.is_int64() );

    jv = 3.14; // assign a double
    assert( jv.kind() == json::kind::double_ );

    jv = nullptr; // assign a null
    assert( jv.is_null() );

I could have gone with this syntax:

    jv = json::null;

by providing my own type and constant:

    namespace json {
    struct null_t {};
    inline static null_t null;

but nullptr is quite close to it and entirely accessible by the common
folk that this library targets, and this avoids an unnecessary
proliferation of small types.


Boost list run by bdawes at, gregod at, cpdaniel at, john at