Boost logo

Boost :

From: Roberto Hinz (robhz786_at_[hidden])
Date: 2019-09-01 13:10:20


On Sun, Sep 1, 2019 at 7:45 AM Bjorn Reese via Boost <boost_at_[hidden]>
wrote:

> On 8/29/19 3:24 PM, Roberto Hinz via Boost wrote:
>
> > auto result = csw.finish();
> > if (result.truncated) {
> > // ...
>
> I suggest that you change the return type of finish() to contain
> the number of element written instead of the truncated boolean.
> This would make outbuf extensible to binary data as well where you
> cannot rely on a terminating zero to tell you how much data has
> been written.
>
> The return type could also have begin()/end() member functions, which
> makes it directly usable with STL algorithms. In that case it would
> also make sense to have data()/size().
>

outbuf can be used to binary data, but the basic_cstr_writer class
in particular may not be suitable for that, since its finish() function
aways writes a terminating zero, requiring an extra space in the
destination string. Perhaps we could add another class template,
`basic_bin_writer`, that would never write a terminating character.

Anyway, the returned result contains a `ptr` member that points to
the end of the string. In order to add begin()/data()/size() functions
basic_cstr_writer would also need to store the initial position,
which would increase its size a little bit. And that's the only reason
why I did not add it, since I think it would not be used most of
time, and the caller already knows the begin anyway.
It's convenience vs tiny cost decision. I will go for the what the
majority prefers.


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