isocpp / isocpp/CppCoreGuidelines
Please clarify the term "efficient" in the context of in-class member initializers
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
C.45: Don't define a default constructor that only initializes data members; use in-class member initializers instead (link) says:
Using in-class member initializers lets the compiler generate the function for you. The compiler-generated function can be more efficient.
Moreover C.48: Prefer in-class initializers to member initializers in constructors for constant initializers (link) says about in-class member initializers:
It leads to the shortest and most efficient code
What is meant by "efficient" in this context? Does it mean to say that the use of in-class initializers leads to making programs faster?
I'm asking specifically because an Abseil C++ Tip from https://abseil.io/tips/61 seems to say exactly the opposite! At the start of its conclusion:
Default member initializers won’t make your program any faster.
(Actually I asked the Abseil team to remove that sentence, but it's still there: https://github.com/abseil/abseil.github.io/pull/423)
I hope you can clarify this issue.
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 with the C.45 and C.48 sections in CppCoreGuidelines.md at the linked lines, then compare their wording with the cited Abseil Tip 61. Clarify what “efficient” means in these guidelines and resolve whether the wording should distinguish generated code, source code, or runtime performance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100