tmp/tmpoki_fz6q/{from.md → to.md}
RENAMED
|
@@ -1,25 +1,48 @@
|
|
| 1 |
-
###
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
|
| 5 |
```
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
*Effects:* If it is possible to fit `size` bytes of storage aligned by
|
| 8 |
`alignment` into the buffer pointed to by `ptr` with length `space`, the
|
| 9 |
function updates `ptr` to represent the first possible address of such
|
| 10 |
storage and decreases `space` by the number of bytes used for alignment.
|
| 11 |
Otherwise, the function does nothing.
|
| 12 |
|
| 13 |
-
*Requires:*
|
| 14 |
-
|
| 15 |
-
- `alignment` shall be a power of two
|
| 16 |
-
- `ptr` shall represent the address of contiguous storage of at least
|
| 17 |
-
`space` bytes
|
| 18 |
-
|
| 19 |
*Returns:* A null pointer if the requested aligned buffer would not fit
|
| 20 |
into the available space, otherwise the adjusted value of `ptr`.
|
| 21 |
|
| 22 |
[*Note 1*: The function updates its `ptr` and `space` arguments so that
|
| 23 |
it can be called repeatedly with possibly different `alignment` and
|
| 24 |
`size` arguments for the same buffer. — *end note*]
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Pointer alignment <a id="ptr.align">[[ptr.align]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
|
| 5 |
```
|
| 6 |
|
| 7 |
+
*Preconditions:*
|
| 8 |
+
|
| 9 |
+
- `alignment` is a power of two
|
| 10 |
+
- `ptr` represents the address of contiguous storage of at least `space`
|
| 11 |
+
bytes
|
| 12 |
+
|
| 13 |
*Effects:* If it is possible to fit `size` bytes of storage aligned by
|
| 14 |
`alignment` into the buffer pointed to by `ptr` with length `space`, the
|
| 15 |
function updates `ptr` to represent the first possible address of such
|
| 16 |
storage and decreases `space` by the number of bytes used for alignment.
|
| 17 |
Otherwise, the function does nothing.
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
*Returns:* A null pointer if the requested aligned buffer would not fit
|
| 20 |
into the available space, otherwise the adjusted value of `ptr`.
|
| 21 |
|
| 22 |
[*Note 1*: The function updates its `ptr` and `space` arguments so that
|
| 23 |
it can be called repeatedly with possibly different `alignment` and
|
| 24 |
`size` arguments for the same buffer. — *end note*]
|
| 25 |
|
| 26 |
+
``` cpp
|
| 27 |
+
template<size_t N, class T>
|
| 28 |
+
[[nodiscard]] constexpr T* assume_aligned(T* ptr);
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
*Mandates:* `N` is a power of two.
|
| 32 |
+
|
| 33 |
+
*Preconditions:* `ptr` points to an object `X` of a type
|
| 34 |
+
similar [[conv.qual]] to `T`, where `X` has alignment `N`
|
| 35 |
+
[[basic.align]].
|
| 36 |
+
|
| 37 |
+
*Returns:* `ptr`.
|
| 38 |
+
|
| 39 |
+
*Throws:* Nothing.
|
| 40 |
+
|
| 41 |
+
[*Note 2*: The alignment assumption on an object `X` expressed by a
|
| 42 |
+
call to `assume_aligned` may result in generation of more efficient
|
| 43 |
+
code. It is up to the program to ensure that the assumption actually
|
| 44 |
+
holds. The call does not cause the compiler to verify or enforce this.
|
| 45 |
+
An implementation might only make the assumption for those operations on
|
| 46 |
+
`X` that access `X` through the pointer returned by
|
| 47 |
+
`assume_aligned`. — *end note*]
|
| 48 |
+
|