Skip to content

Revise the design around io_result #425

Description

@akrzemi1

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions