From acf66d8c7e98ab188010bcd74f428833f5e32724 Mon Sep 17 00:00:00 2001 From: Dawn Perchik Date: Tue, 14 Nov 2023 20:24:55 -0800 Subject: [PATCH] P2819R2 Add tuple protocol to complex --- source/numerics.tex | 57 ++++++++++++++++++++++++++++++++++++++++++++ source/support.tex | 2 +- source/utilities.tex | 2 +- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/source/numerics.tex b/source/numerics.tex index 50fbb0d68a..34e3ea944d 100644 --- a/source/numerics.tex +++ b/source/numerics.tex @@ -289,6 +289,20 @@ template constexpr complex tan (const complex&); template constexpr complex tanh (const complex&); + // \ref{complex.tuple}, tuple interface + template struct tuple_size; + template struct tuple_element; + template struct tuple_size>; + template struct tuple_element>; + template + constexpr T& get(complex&) noexcept; + template + constexpr T&& get(complex&&) noexcept; + template + constexpr const T& get(const complex&) noexcept; + template + constexpr const T&& get(const complex&&) noexcept; + // \ref{complex.literals}, complex literals inline namespace literals { inline namespace complex_literals { @@ -1121,6 +1135,49 @@ The complex hyperbolic tangent of \tcode{x}. \end{itemdescr} +\rSec2[complex.tuple]{Tuple interface} + +\indexlibraryglobal{tuple_size}% +\indexlibraryglobal{tuple_element}% +\begin{itemdecl} +template +struct tuple_size> : integral_constant {}; + +template +struct tuple_element> { + using type = T; +}; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\mandates +\tcode{I < 2} is \tcode{true}. +\end{itemdescr} + +\indexlibrarymember{get}{complex}% +\begin{itemdecl} +template + constexpr T& get(complex& z) noexcept; +template + constexpr T&& get(complex&& z) noexcept; +template + constexpr const T& get(const complex& z) noexcept; +template + constexpr const T&& get(const complex&& z) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\mandates +\tcode{I < 2} is \tcode{true}. + +\pnum +\returns +A reference to the real part of \tcode{z} if \tcode{I == 0} is \tcode{true}, +otherwise a reference to the imaginary part of \tcode{z}. +\end{itemdescr} + \rSec2[cmplx.over]{Additional overloads} \pnum diff --git a/source/support.tex b/source/support.tex index f867e7d5f9..3d4e9ac495 100644 --- a/source/support.tex +++ b/source/support.tex @@ -787,7 +787,7 @@ #define @\defnlibxname{cpp_lib_transparent_operators}@ 201510L // freestanding, also in \libheader{memory}, \libheader{functional} #define @\defnlibxname{cpp_lib_tuple_element_t}@ 201402L // freestanding, also in \libheader{tuple} -#define @\defnlibxname{cpp_lib_tuple_like}@ 202207L +#define @\defnlibxname{cpp_lib_tuple_like}@ 202311L // also in \libheader{utility}, \libheader{tuple}, \libheader{map}, \libheader{unordered_map} #define @\defnlibxname{cpp_lib_tuples_by_type}@ 201304L // freestanding, also in \libheader{utility}, \libheader{tuple} #define @\defnlibxname{cpp_lib_type_identity}@ 201806L // freestanding, also in \libheader{type_traits} diff --git a/source/utilities.tex b/source/utilities.tex index 60be15fec2..6e9c381be5 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -1612,7 +1612,7 @@ A type \tcode{T} models and satisfies the exposition-only concept \exposconcept{tuple-like} if \tcode{remove_cvref_t} is a specialization of -\tcode{array}, \tcode{pair}, \tcode{tuple}, or \tcode{ranges::subrange}. +\tcode{array}, \tcode{complex}, \tcode{pair}, \tcode{tuple}, or \tcode{ranges::subrange}. \end{itemdescr} \rSec2[tuple.tuple]{Class template \tcode{tuple}}