[intro.object] Example for p10
Open
Nobody has claimed this yet.
P3-Other
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
Description
I think p10 could need an example, ideally on which highlights the idiom of using std::launder to force the creation of one particular type of object.
int x;
new (storage) std::byte[sizeof(x)]; // implicitly begin the lifetime of objects in x
*reinterpret_cast<char*>(&x); // unspecified whether placement new created
// an int object inside x, float, char[], or any other objects
std::memmove(&x, &x, sizeof(x)); // transparently replace ([basic.life]) x with another object
x = 0; // the new object must be of type (no cv) int because
// only that may give the program well-defined behavior
std::memmove(&x, &x, sizeof(x)); // begin the lifetime of one or multiple objects in the storage of x
std::launder(reinterpret_cast<short*>(&x)); // created object at &x must be of type short int
x = 0; // undefined behavior
Contributor guide
No contributing guide indexed for this repository
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 p10 of [intro.object] and the surrounding object-lifetime wording. Evaluate whether an example centered on std::launder clearly illustrates forcing the creation of one particular object type, and consider the shown placement-new and std::memmove cases. Done when the example is integrated into that paragraph and accurately reflects the intended rules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100