isocpp / isocpp/CppCoreGuidelines

F.16 what exactly is cheap to copy for the purposes of passing "by value"?

Open
#1,421 10 comments 0 reactions 1 assignee View on GitHub

@cubbimew is already working on this.

Since May 9, 2019.

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

Description

F.16 says:

What is “cheap to copy” depends on the machine architecture, but two or three words (doubles, pointers, references) are usually best passed by value.

I need clarification on what the guidelines mean by "two or three words". I have two conflicting interpretations:

  • 1 word == sizeof one double, pointer or reference and thus objects two or three times this size should generally be passed by value (such as string_view or shared_ptr)
  • "two or three words" is the sizeof one double, pointer or reference and thus anything larger than that should be passed by reference.

I find the first interpretation more logical. Can the text be clarified? Do you accept PRs for fixing this and clarifying that the first interpretation is correct?

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.