This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

130
cppdraft/ptr/align.md Normal file
View File

@@ -0,0 +1,130 @@
[ptr.align]
# 20 Memory management library [[mem]](./#mem)
## 20.2 Memory [[memory]](memory#ptr.align)
### 20.2.5 Pointer alignment [ptr.align]
[🔗](#lib:align)
`void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L946)
*Preconditions*:
- [(1.1)](#1.1)
alignment is a power of two
- [(1.2)](#1.2)
ptr represents the address of contiguous storage of at leastspace bytes
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L957)
*Effects*: If it is possible to fit size bytes
of storage aligned by alignment into the buffer pointed to byptr with length space, the function updatesptr to represent the first possible address of such storage
and decreases space by the number of bytes used for alignment[.](#2.sentence-1)
Otherwise, the function does nothing[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L966)
*Returns*: A null pointer if the requested aligned buffer
would not fit into the available space, otherwise the adjusted value
of ptr[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L972)
[*Note [1](#note-1)*:
The function updates its ptr and space arguments so that it can be called repeatedly
with possibly different alignment and size arguments for the same buffer[.](#4.sentence-1)
— *end note*]
[🔗](#lib:assume_aligned)
`template<size_t N, class T>
constexpr T* assume_aligned(T* ptr);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L988)
*Mandates*: N is a power of two[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L992)
*Preconditions*: ptr points to an object X of
a type similar ([[conv.qual]](conv.qual "7.3.6Qualification conversions")) to T,
where X has alignment N ([[basic.align]](basic.align "6.8.3Alignment"))[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L998)
*Returns*: ptr[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1002)
*Throws*: Nothing[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1006)
[*Note [2](#note-2)*:
The alignment assumption on an object X expressed by a call to assume_aligned might result in generation of more efficient code[.](#9.sentence-1)
It is up to the program to ensure that the assumption actually holds[.](#9.sentence-2)
The call does not cause the implementation to verify or enforce this[.](#9.sentence-3)
An implementation might only make the assumption
for those operations on X that access X through the pointer returned by assume_aligned[.](#9.sentence-4)
— *end note*]
[🔗](#lib:is_sufficiently_aligned)
`template<size_t Alignment, class T>
bool is_sufficiently_aligned(T* ptr);
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1026)
*Preconditions*: p points to
an object X of a type similar ([[conv.qual]](conv.qual "7.3.6Qualification conversions")) to T[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1031)
*Returns*: true if X has alignment at least Alignment,
otherwise false[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1036)
*Throws*: Nothing[.](#12.sentence-1)

69
cppdraft/ptr/launder.md Normal file
View File

@@ -0,0 +1,69 @@
[ptr.launder]
# 17 Language support library [[support]](./#support)
## 17.6 Dynamic memory management [[support.dynamic]](support.dynamic#ptr.launder)
### 17.6.5 Pointer optimization barrier [ptr.launder]
[🔗](#lib:launder)
`template<class T> constexpr T* launder(T* p) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3160)
*Mandates*: !is_function_v<T> && !is_void_v<T> is true[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3164)
*Preconditions*: p represents the address *A* of a byte in memory[.](#2.sentence-1)
An object *X* that is within its [lifetime](basic.life#def:lifetime "6.8.4Lifetime[basic.life]") and whose type is [similar](conv.qual#def:similar_types "7.3.6Qualification conversions[conv.qual]") to T is located at the address *A*[.](#2.sentence-2)
All bytes of storage that would be
reachable through ([[basic.compound]](basic.compound "6.9.4Compound types")) the result
are reachable through p[.](#2.sentence-3)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3174)
*Returns*: A value of type T* that points to *X*[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3178)
*Remarks*: An invocation of this function
may be used in a core constant expression
if and only if the (converted) value of its argument
may be used in place of the function invocation[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3185)
[*Note [1](#note-1)*:
If a new object is created
in storage occupied by an existing object of the same type,
a pointer to the original object
can be used to refer to the new object
unless its complete object is a const object or it is a base class subobject;
in the latter cases,
this function can be used to obtain a usable pointer to the new object[.](#5.sentence-1)
See [[basic.life]](basic.life "6.8.4Lifetime")[.](#5.sentence-2)
— *end note*]
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3197)
[*Example [1](#example-1)*: struct X { int n; };const X *p = new const X{3};const int a = p->n;new (const_cast<X*>(p)) const X{5}; // p does not point to new object ([[basic.life]](basic.life "6.8.4Lifetime")) because its type is constconst int b = p->n; // undefined behaviorconst int c = std::launder(p)->n; // OK — *end example*]