Boost logo

Boost :

From: Zach Laine (whatwasthataddress_at_[hidden])
Date: 2019-12-02 17:38:45


On Thu, Nov 28, 2019 at 6:18 PM Andrey Semashev via Boost <
boost_at_[hidden]> wrote:

> On 2019-11-29 01:44, Zach Laine via Boost wrote:
> >
> > Ok, I understand your point a bit better now I think. Is it the
> > unboundedly-large nature of a NTBS that has you concerned? That is, do
> you
> > think that op+=(char) should assert and op+=(char const *) should throw?
> > That position makes sense to me, thought I don't share it -- though I
> think
> > that's just taste. However, I cannot imagine why I'd ever want
> op+=(char)
> > or op+=(string_view) to throw.
>
> IIRC, append/insert/push_back will throw with any container or
> std::string, if the result exceeds max_size(). It is only natural if
> fixed_string does the same, it is the expected behavior.
>
> You can argue for a separate set of unsafe insert methods that don't
> perform the check and exhibit undefined behavior if the resulting length
> exceeds the limit. But it should be very clear that the user must ensure
> himself that it doesn't happen.
>

I don't find it natural that a type whose size is statically known and a
type whose size is not statically known have the same relationship to user
code (preconditions, use of UB vs. exceptions, etc.).

Zach


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