Skip to content

Commit 6fc76aa

Browse files
authored
Merge 2022-02 LWG Motion 6
P1413R3 Deprecate std::aligned_storage and std::aligned_union
2 parents d9718e8 + 55b4e4d commit 6fc76aa

File tree

2 files changed

+76
-52
lines changed

2 files changed

+76
-52
lines changed

source/future.tex

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,14 @@
13691369
namespace std {
13701370
template<class T> struct is_pod;
13711371
template<class T> inline constexpr bool is_pod_v = is_pod<T>::value;
1372+
template<size_t Len, size_t Align = @\exposid{default-alignment}@> // \seebelow
1373+
struct aligned_storage;
1374+
template<size_t Len, size_t Align = @\exposid{default-alignment}@> // \seebelow
1375+
using @\libglobal{aligned_storage_t}@ = typename aligned_storage<Len, Align>::type;
1376+
template<size_t Len, class... Types>
1377+
struct aligned_union;
1378+
template<size_t Len, class... Types>
1379+
using @\libglobal{aligned_union_t}@ = typename aligned_union<Len, Types...>::type;
13721380
}
13731381
\end{codeblock}
13741382

@@ -1403,6 +1411,74 @@
14031411
\end{note}
14041412
\end{itemdescr}
14051413

1414+
\indexlibraryglobal{aligned_storage}%
1415+
\begin{itemdecl}
1416+
template<size_t Len, size_t Align = @\exposid{default-alignment}@>
1417+
struct aligned_storage;
1418+
\end{itemdecl}
1419+
1420+
\begin{itemdescr}
1421+
\pnum
1422+
The value of \exposid{default-alignment} is the most
1423+
stringent alignment requirement for any object type whose size
1424+
is no greater than \tcode{Len}\iref{basic.types}.
1425+
1426+
\pnum
1427+
\mandates
1428+
\tcode{Len} is not zero.
1429+
\tcode{Align} is equal to \tcode{alignof(T)} for some type \tcode{T} or
1430+
to \exposid{default-alignment}.
1431+
1432+
\pnum
1433+
The member typedef \tcode{type} is a trivial standard-layout type
1434+
suitable for use as uninitialized storage for any object
1435+
whose size is at most \tcode{Len} and
1436+
whose alignment is a divisor of \tcode{Align}.
1437+
1438+
\pnum
1439+
\begin{note}
1440+
Uses of \tcode{aligned_storage<Len, Align>::type} can be replaced
1441+
by an array \tcode{std::byte[Len]} declared with \tcode{alignas(Align)}.
1442+
\end{note}
1443+
1444+
\pnum
1445+
\begin{note}
1446+
A typical implementation would define \tcode{aligned_storage} as:
1447+
\begin{codeblock}
1448+
template<size_t Len, size_t Alignment>
1449+
struct aligned_storage {
1450+
typedef struct {
1451+
alignas(Alignment) unsigned char __data[Len];
1452+
} type;
1453+
};
1454+
\end{codeblock}
1455+
\end{note}
1456+
1457+
\end{itemdescr}
1458+
1459+
\indexlibraryglobal{aligned_union}%
1460+
\begin{itemdecl}
1461+
template<size_t Len, class... Types>
1462+
struct aligned_union;
1463+
\end{itemdecl}
1464+
1465+
\begin{itemdescr}
1466+
\pnum
1467+
\mandates
1468+
At least one type is provided.
1469+
Each type in the template parameter pack \tcode{Types}
1470+
is a complete object type.
1471+
1472+
\pnum
1473+
The member typedef \tcode{type} is a trivial standard-layout type
1474+
suitable for use as uninitialized storage for any object
1475+
whose type is listed in \tcode{Types};
1476+
its size shall be at least \tcode{Len}.
1477+
The static member \tcode{alignment_value}
1478+
is an integral constant of type \tcode{size_t}
1479+
whose value is the strictest alignment of all types listed in \tcode{Types}.
1480+
\end{itemdescr}
1481+
14061482
\rSec1[depr.tuple]{Tuple}
14071483

14081484
\pnum

source/utilities.tex

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19635,9 +19635,6 @@
1963519635

1963619636
// \ref{meta.trans.other}, other transformations
1963719637
template<class T> struct type_identity;
19638-
template<size_t Len, size_t Align = @\textit{default-alignment}@> // see \ref{meta.trans.other}
19639-
struct aligned_storage;
19640-
template<size_t Len, class... Types> struct aligned_union;
1964119638
template<class T> struct remove_cvref;
1964219639
template<class T> struct decay;
1964319640
template<bool, class T = void> struct enable_if;
@@ -19653,10 +19650,6 @@
1965319650

1965419651
template<class T>
1965519652
using @\libglobal{type_identity_t}@ = typename type_identity<T>::type;
19656-
template<size_t Len, size_t Align = @\textit{default-alignment}@> // see \ref{meta.trans.other}
19657-
using @\libglobal{aligned_storage_t}@ = typename aligned_storage<Len, Align>::type;
19658-
template<size_t Len, class... Types>
19659-
using @\libglobal{aligned_union_t}@ = typename aligned_union<Len, Types...>::type;
1966019653
template<class T>
1966119654
using @\libglobal{remove_cvref_t}@ = typename remove_cvref<T>::type;
1966219655
template<class T>
@@ -21095,36 +21088,6 @@
2109521088
&
2109621089
The member typedef \tcode{type} names the type \tcode{T}. \\ \rowsep
2109721090

21098-
\indexlibraryglobal{aligned_storage}%
21099-
\tcode{template<size_t Len,\br
21100-
size_t Align\br
21101-
= \textit{default-alignment}>\br
21102-
struct aligned_storage;}
21103-
&
21104-
The value of \textit{default-alignment} shall be the most
21105-
stringent alignment requirement for any object type whose size
21106-
is no greater than \tcode{Len}\iref{basic.types}.
21107-
The member typedef \tcode{type} shall be a trivial standard-layout type
21108-
suitable for use as uninitialized storage for any object whose size
21109-
is at most \tcode{Len} and whose alignment is a divisor of \tcode{Align}.\br
21110-
\mandates \tcode{Len} is not zero. \tcode{Align} is equal to
21111-
\tcode{alignof(T)} for some type \tcode{T} or to \textit{default-alignment}.\\ \rowsep
21112-
21113-
\indexlibraryglobal{aligned_union}%
21114-
\tcode{template<size_t Len,\br
21115-
class... Types>\br
21116-
struct aligned_union;}
21117-
&
21118-
The member typedef \tcode{type} shall be a trivial standard-layout type suitable for use as
21119-
uninitialized storage for any object whose type is listed in \tcode{Types};
21120-
its size shall be at least \tcode{Len}. The static member \tcode{alignment_value}
21121-
shall be an integral constant of type \tcode{size_t} whose value is the
21122-
strictest alignment of all types listed in \tcode{Types}.\br
21123-
\mandates At least one type is provided.
21124-
Each type in the template parameter pack \tcode{Types}
21125-
is a complete object type.
21126-
\\ \rowsep
21127-
2112821091
\indexlibraryglobal{remove_cvref}%
2112921092
\tcode{template<class T>\br struct remove_cvref;}
2113021093
&
@@ -21235,21 +21198,6 @@
2123521198
denotes the type \tcode{unwrap_reference_t<decay_t<T>>}.\\
2123621199
\end{libreqtab2a}
2123721200

21238-
\indexlibraryglobal{aligned_storage}%
21239-
\pnum
21240-
\begin{note}
21241-
A typical implementation would define \tcode{aligned_storage} as:
21242-
21243-
\begin{codeblock}
21244-
template<size_t Len, size_t Alignment>
21245-
struct aligned_storage {
21246-
typedef struct {
21247-
alignas(Alignment) unsigned char __data[Len];
21248-
} type;
21249-
};
21250-
\end{codeblock}
21251-
\end{note}
21252-
2125321201
\pnum
2125421202
In addition to being available via inclusion
2125521203
of the \tcode{<type_traits>} header, the templates

0 commit comments

Comments
 (0)