Skip to content

Commit 2f46621

Browse files
Dawn Perchikzygoloid
authored andcommitted
P1007R3 std::assume_aligned
[memory.syn] Merged the new function in with [ptr.align] and renamed the section to "Pointer alignment". [ptr.aligned] Added "a" before "type similar".
1 parent c734308 commit 2f46621

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

source/utilities.tex

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6572,8 +6572,10 @@
65726572
void undeclare_no_pointers(char* p, size_t n);
65736573
pointer_safety get_pointer_safety() noexcept;
65746574

6575-
// \ref{ptr.align}, pointer alignment function
6575+
// \ref{ptr.align}, pointer alignment
65766576
void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
6577+
template<size_t N, class T>
6578+
[[nodiscard]] constexpr T* assume_aligned(T* ptr);
65776579

65786580
// \ref{allocator.tag}, allocator argument tag
65796581
struct allocator_arg_t { explicit allocator_arg_t() = default; };
@@ -7128,7 +7130,7 @@
71287130
\end{itemdescr}
71297131

71307132

7131-
\rSec2[ptr.align]{Align}
7133+
\rSec2[ptr.align]{Pointer alignment}
71327134

71337135
\indexlibrary{\idxcode{align}}%
71347136
\begin{itemdecl}
@@ -7166,6 +7168,44 @@
71667168
arguments for the same buffer. \end{note}
71677169
\end{itemdescr}
71687170

7171+
\indexlibrary{\idxcode{assume_aligned}}%
7172+
\begin{itemdecl}
7173+
template<size_t N, class T>
7174+
[[nodiscard]] constexpr T* assume_aligned(T* ptr);
7175+
\end{itemdecl}
7176+
7177+
\begin{itemdescr}
7178+
\pnum
7179+
\mandates
7180+
\tcode{N} is a power of two.
7181+
7182+
\pnum
7183+
\expects
7184+
\tcode{ptr} points to an object \tcode{X} of
7185+
a type similar\iref{conv.qual} to \tcode{T},
7186+
where \tcode{X} has alignment \tcode{N}\iref{basic.align}.
7187+
7188+
\pnum
7189+
\returns
7190+
\tcode{ptr}.
7191+
7192+
\pnum
7193+
\throws
7194+
Nothing.
7195+
7196+
\pnum
7197+
\begin{note}
7198+
The alignment assumption on an object \tcode{X}
7199+
expressed by a call to \tcode{assume_aligned}
7200+
may result in generation of more efficient code.
7201+
It is up to the program to ensure that the assumption actually holds.
7202+
The call does not cause the compiler to verify or enforce this.
7203+
An implementation might only make the assumption
7204+
for those operations on \tcode{X} that access \tcode{X}
7205+
through the pointer returned by \tcode{assume_aligned}.
7206+
\end{note}
7207+
\end{itemdescr}
7208+
71697209
\rSec2[allocator.tag]{Allocator argument tag}
71707210

71717211
\indexlibrary{\idxcode{allocator_arg_t}}%

0 commit comments

Comments
 (0)