Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2019-12-04 16:05:55


Phil Endecott wrote:
> Peter Dimov <pdimov_at_[hidden]> wrote:
>
> > Krystian Stasiowski wrote:
> >
> >> - Empty class specialization for N = 0: Implemented
> >
> > I don't like this change. A special case for close to zero benefit that
> > changes the semantics of data() to not be unique per instance.
>
> I would hope to see close to the same semantics as std::array<T,0>, which
> I believe allows data() to return nullptr.

nullptr is invalid here, because the string is null-terminated.

> > Storing the size (as capacity - size) in the last char for N < 256 will
> > have more impact, but I'm not sure that it too is worth the added
> > complexity.
>
> Why the last char, rather than always having the size (of whatever
> appropriate type) first? Is the idea that this makes data() and c_str()
> essentially no-ops?

The idea here is that you win one byte by reusing the last byte of the
storage as the size, overlapping it with the null terminator in the size()
== N case (because capacity - size becomes 0).


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