isocpp / isocpp/CppCoreGuidelines
Provide support for "safe" and "simple" binary I/O in the GSL
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?
- c++ - How to use new std::byte type in places where old-style unsigned char is needed? - Stack Overflow
- c++ - How to use something like
std::basic_istream- Stack Overflow - there was a proposal to extend iostream support for
std::byte, but that got abandoned: P2146 Modern std::byte stream IO for C++ · Issue #860 · cplusplus/papers (github.com)
So are the user's suggestions regarding byte buffers simply something the Core Guidelines do not intend to support?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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