While the naming is revised separately, I would like to rehash the idea of returning a product type of error_code with other things.
It looks to me like the idea of returning tuple<error_code, size_t> only makes sense for stream reads and writes. By streams, I mean ReadStream, WriteStream and their derivatives: Stream, ReadSource, WriteSink and read_some_at in random_access_file (which I am surprised not to find part of the stream concept system). Any other function in the Capy-family uses error_code to represent either error or data.
While more functions return tuple<error_code, something>, the something uses dummy, meaningless values upon non-zero error_code. This is looks like a desperate attempt to fit into the tuple that is inadequate in these contexts.
In all occurrences of io_result<> its number of arguments is either zero or one. In the cases where it is one:
- we are either in the stream read or write operation, and the argument is of type
size_t, or
- we are using dummy, meaningless values when
error_code is non-zero, in order to try to use tuple as a sum type.
So, this use of a tuple is an overreach. It blurs the difference between funcitons signalling an error, and streams reads/writes returning a two-fold information. This is also why when_all and when_any cannot be designed satisfactorily.
I would recommend separating the stream read/write contract from other functions' contract.
While the naming is revised separately, I would like to rehash the idea of returning a product type of
error_codewith other things.It looks to me like the idea of returning
tuple<error_code, size_t>only makes sense for stream reads and writes. By streams, I meanReadStream,WriteStreamand their derivatives:Stream,ReadSource,WriteSinkandread_some_atinrandom_access_file(which I am surprised not to find part of the stream concept system). Any other function in the Capy-family useserror_codeto represent either error or data.While more functions return
tuple<error_code, something>, thesomethinguses dummy, meaningless values upon non-zeroerror_code. This is looks like a desperate attempt to fit into thetuplethat is inadequate in these contexts.In all occurrences of
io_result<>its number of arguments is either zero or one. In the cases where it is one:size_t, orerror_codeis non-zero, in order to try to usetupleas a sum type.So, this use of a tuple is an overreach. It blurs the difference between funcitons signalling an error, and streams reads/writes returning a two-fold information. This is also why
when_allandwhen_anycannot be designed satisfactorily.I would recommend separating the stream read/write contract from other functions' contract.