Boost logo

Boost :

From: Vinnie Falco (vinnie.falco_at_[hidden])
Date: 2023-02-07 15:34:06


On Tue, Feb 7, 2023 at 5:50 AM Peter Dimov via Boost
<boost_at_[hidden]> wrote:
> We've been thinking about a type `json::value_view` that is to `json::value`
> what `string_view` is to `string` - a way to get a "reference" to a type
> supported natively by `value_from` that looks like a `json::value` without
> having to create a `json::value` temporary and copy everything.

On record, I am not terribly fond of this solution. Peter managed to
convince me of the importance of a solution but I am not sure that it
should be a JSON thing. Boost.JSON is designed for maximum
compatibility with Node.js and other non-C++ languages. It is designed
for fast serialization and parsing using the json::value variant type.
It is not designed for the use-cases contemplated by the
aforementioned value_view.

Instead I would prefer a more general type-erasing facility which can
be used on user-defined types. The facility would need a variant-like
type (the replacement for boost::json::value) that can capture any C++
builtin type at full fidelity (which Boost.JSON cannot do, and was not
designed to do). For example it should capture 128 bit integers, or
floats, or shorts, as their native type. This facility could provide
type traits to detect things such as is_optional_like,
is_contiguous_array_of, is_key_value_map and so forth. And there could
be the necessary wrappers to type-erase these concept-driven things.

There is a working prototype of the json::value_view described above
but it has limitations. It only works for certain kinds of iterators
(those that can be type-erased without allocating memory). And other
things. I believe there is room in Boost.Describe for this facility
(or, perhaps another library, but Describe is a logical place for
several reasons).

Thanks


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk