isocpp / isocpp/CppCoreGuidelines
gsl::copy is not in the Core Guidelines
@hsutter is already working on this.
Since Oct 13, 2023.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
Microsoft's GSL currently has a definition for the gsl::copy function. However, gsl::copy isn't properly mentioned anywhere in the Core Guidelines, including the GSL: Guidelines support library section.
Should this function be added to the CG with a specification and corresponding rule?
History of the current implementation
gsl::copy was first brought up in std::copy doesn't work on 2 span · Issue #248 · microsoft/GSL (github.com), in reference to an example code snippet mentioned in I.13: Do not pass an array as a single pointer:
Alternative Consider using explicit spans:
void copy(span<const T> r, span<T> r2); // copy r to r2
It was then implemented in PR Add a copy function for span as mentioned in issue #248 by MikeGitb · Pull Request #344 · microsoft/GSL (github.com), eventually leading to the current implementation in Microsoft's GSL.
Note: there is also another instance of this idea in I.24: Avoid adjacent parameters that can be invoked by the same arguments in either order with different meaning, except with the name name copy_n:
Alternative Don’t pass arrays as pointers, pass an object representing a range (e.g., a
span):void copy_n(span<const T> p, span<T> q); // copy from p to q
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.
Assessment
This issue has not been assessed yet.