1

I am trying to write some example of a concept that requires implementing a "read" method. This "read" method would take a number of bytes to read and an output iterator to write the data. So far it looks like this:

template <typename T>
concept DataSourceReader = requires (T reader, std::size_t bytes_to_read) {
    { reader.read(bytes_to_read, std::output_iterator<std::uint8_t>) } -> std::same_as<std::size_t>;
};

However it has multiple issues:

  • std::output_iterator requires 2 template arguments but I can't figure out what they are
  • the std::output_iterator argument does not put any constraints (e.g. I can call with any types)

It is also not clear why bytes_to_read need to be in top when { reader.read(5, ...) } works but { reader.read(std::size_t, ...) } does not.

It would seem ok to allow { reader.read(std::same_as<std::size_t>, ...) } since that's how return types can be constrained but it is also wrong.

domtop
  • 41
  • 4

0 Answers0