-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
375 - Did you know C++26 added support constexpr placement new?
- Loading branch information
1 parent
bc5c674
commit f79781c
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<details open><summary>Info</summary><p> | ||
|
||
* **Did you know C++26 added support constexpr placement new? | ||
|
||
* https://wg21.link/P2747 | ||
|
||
</p></details><details open><summary>Example</summary><p> | ||
|
||
```cpp | ||
static_assert([] { | ||
std::array<int, 1024> storage{}; | ||
auto ptr = new (storage.data()) int{42}; | ||
return 42 == *ptr; | ||
}()); | ||
|
||
static_assert([] { | ||
std::array<int, 1024> storage{}; | ||
auto ptr = std::construct_at<int>(storage.data(), 42); | ||
return 42 == *ptr; | ||
}()); | ||
``` | ||
> https://godbolt.org/z/61Kcjz1s6 | ||
</p></details> |