Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2020-09-16 15:53:35

Vinnie Falco wrote:

> That is easy to say but what do you do about this function which returns a
> reference:
> inline value& array::operator[]( std::size_t pos ) noexcept;
> What do you do if you have an array of int (scalar) and someone accesses
> an element in the middle and assigns a string to it?

The only possible answer is "copy the entire thing into value[]". This may
or may not be acceptable. I would think that if you have an array of 8044
ints, assigning a string somewhere in the middle would be a rare occurrence,
but who knows.

The upside is that an array of ints would consume significantly less memory
than today; this is often important and we've already seen that for a subset
of users, memory consumption is _the_ important metric. (It would also make
value_to<vector<int>> infinitely faster.)

The downside of course is that when someone assigns a single non-int
somewhere, or even just invokes the non-const op[] without assigning a
non-int, or the non-const begin(), the whole thing reallocates. This would
kill the noexcept, at the very minimum. There's a thing to be said here
about returning references to internal state, but consistency has its

For CBOR 1.0, I'd just reject binary values on parsing. That's still much
more useful than not having it.

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