isocpp / isocpp/CppCoreGuidelines

Provide support for "safe" and "simple" binary I/O in the GSL

Open
#2,067 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

What are the editors' views on the GSL user issue Provide a "safe" and "simple" way for binary I/O · Issue #1104 · microsoft/GSL (github.com)?. The Microsoft GSL implementation always follows the interfaces defined by the Core Guidelines, but in this case the user is asking about interfaces not-yet specified in these guidelines, hence me forwarding the question here.

Some thoughts:

For the proposed solution of creating read and write overloads, can we simply create overloads for << and >> for gsl::span<char>?

// Sample implementation for read
std::istream& operator>>(std::istream& i, gsl::span<char> s)
{
    i.read(s.data(), s.size());
    return i;
}

These overloads would align with ES.2: Prefer suitable abstractions to direct use of language features, which encourages the use of >> and << over the messier read and write interfaces.

Note that the current gsl::span policy is to match the existing interface of std::span, except for bounds checking. The existing implementation of std::span does not have overloads for >> nor <<.

Regarding the points on byte buffers represented as gsl::span<gsl::byte>, it seems like buffers of std::byte were never intended to be used with the iostream library?

So are the user's suggestions regarding byte buffers simply something the Core Guidelines do not intend to support?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked Microsoft GSL issue #1104 and the discussion of gsl::span, std::span, iostream overloads, and byte buffers in this issue. Determine whether the Core Guidelines should specify or endorse safe binary I/O interfaces; done means an agreed editor position or a documented guideline direction.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.