cplusplus / cplusplus/draft

[intro.object] Example for p10

Open
#6,429 1 comment 0 reactions 0 assignees View on GitHub

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

  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.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.