C++ Logo

sg16

Advanced search

Re: [SG16-Unicode] std::byte based I/O library

From: Lyberta <lyberta_at_[hidden]>
Date: Thu, 07 Feb 2019 19:59:00 +0000
> There should be no "text IO". Binding attributes on stream objects to
> "handle text" is the mistake IO streams made; it absolutely muddled the
> concerns of IO streams and turned them into stateful messes on the same
> level of floating point and having to save / restore FP registers after
> each call or specific use in order to not break everything downstream /
> used after you made a few calls with specific "sticky" flags.

So do you want to pass the state explicitly such as

std::io::read(stream, state, variable);

My idea is a bit of compromise that I put everything in a single object
and provide a simple accessor function to change it such as

auto my_state = stream.state();
// ...
// Change state
// ...
stream.state() = my_state;

That way we still have the convenient syntax of

std::io::read(stream, variable);

> If you want IO in your text library, make it a single, atomic call
> where all the information required to serialize the text properly is done
> in a single function.

I'm totally fine with this design but I wonder if anyone actually has a
use case where they can't just parse all the text into string at once.
But I'm fine with skipping this use case for now.


Received on 2019-02-07 20:59:16