Skip to content

Commit

Permalink
P2819R2 Add tuple protocol to complex
Browse files Browse the repository at this point in the history
  • Loading branch information
burblebee committed Nov 15, 2023
1 parent ecbeb5a commit 39a34b8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
57 changes: 57 additions & 0 deletions source/numerics.tex
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,20 @@
template<class T> constexpr complex<T> tan (const complex<T>&);
template<class T> constexpr complex<T> tanh (const complex<T>&);

// \ref{complex.tuple}, tuple interface
template<class T> struct tuple_size;
template<size_t I, class T> struct tuple_element;
template<class T> struct tuple_size<complex<T>>;
template<size_t I, class T> struct tuple_element<I, complex<T>>;
template<size_t I, class T>
constexpr T& get(complex<T>&) noexcept;
template<size_t I, class T>
constexpr T&& get(complex<T>&&) noexcept;
template<size_t I, class T>
constexpr const T& get(const complex<T>&) noexcept;
template<size_t I, class T>
constexpr const T&& get(const complex<T>&&) noexcept;

// \ref{complex.literals}, complex literals
inline namespace literals {
inline namespace complex_literals {
Expand Down Expand Up @@ -1121,6 +1135,49 @@
The complex hyperbolic tangent of \tcode{x}.
\end{itemdescr}

\rSec2[complex.tuple]{Tuple interface}

\indexlibrarymember{tuple_size}{complex}%
\indexlibrarymember{tuple_element}{complex}%
\begin{itemdecl}
template<class T>
struct tuple_size<complex<T>> : integral_constant<size_t, 2> {};

template<size_t I, class T>
struct tuple_element<I, complex<T>> {
using type = T;
};
\end{itemdecl}

\begin{itemdescr}
\pnum
\mandates
\tcode{I < 2} is \tcode{true}.
\end{itemdescr}

\indexlibrarymember{get}{complex}%
\begin{itemdecl}
template<size_t I, class T>
constexpr T& get(complex<T>& z) noexcept;
template<size_t I, class T>
constexpr T&& get(complex<T>&& z) noexcept;
template<size_t I, class T>
constexpr const T& get(const complex<T>& z) noexcept;
template<size_t I, class T>
constexpr const T&& get(const complex<T>&& 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
Expand Down
2 changes: 1 addition & 1 deletion source/support.tex
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,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}
Expand Down
2 changes: 1 addition & 1 deletion source/utilities.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@
A type \tcode{T} models and satisfies
the exposition-only concept \exposconcept{tuple-like}
if \tcode{remove_cvref_t<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}}
Expand Down

0 comments on commit 39a34b8

Please sign in to comment.