Boost logo

Boost :

From: Roberto Hinz (robhz786_at_[hidden])
Date: 2019-09-12 17:21:18


On Tue, Sep 10, 2019 at 11:05 PM Vinnie Falco <vinnie.falco_at_[hidden]>
wrote:

> `std::basic_ostream` is actually quite usable once you figure out how
> it works
>

Let me illustrate why I disagree with that. Suppose you want to
implement a base64 encoder. You want it to be fast, agnostic,
and simple to use. Now suppose you adopt `std::ostream` as
the destination type:

  void to_base64( std::ostream& dest, const std::byte* src, std::size_t
count );

You will face two issues:

1) It doesn't matter how well you (as the library author) understand
   basic_ostream. The *user* needs to implement derivates of
   basic_ostream to customize the destination types.

2) It's impossible to achieve a decent performance. If you used
   `outbuf` you could write directly into the buffer. But with
   `std::ostream` you have to call member functions like `put`
   or `write` to for each little piece of the content, or to use an
   additional intermediate buffer.

And this is far to be a specific use case. The same issues apply
for any kind of encoding, binary or text.


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