From e0e8457312ba20071ebeeb067c39b785bcece776 Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Wed, 9 Jun 2021 20:13:53 +0200 Subject: [PATCH] P2231R1 Missing constexpr in std::optional and std::variant --- source/support.tex | 4 +-- source/utilities.tex | 84 +++++++++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/source/support.tex b/source/support.tex index 28bfb09629..52aed1c36c 100644 --- a/source/support.tex +++ b/source/support.tex @@ -655,7 +655,7 @@ // \libheader{unordered_map}, \libheader{unordered_set}, \libheader{vector} #define @\defnlibxname{cpp_lib_not_fn}@ 201603L // also in \libheader{functional} #define @\defnlibxname{cpp_lib_null_iterators}@ 201304L // also in \libheader{iterator} -#define @\defnlibxname{cpp_lib_optional}@ 201606L // also in \libheader{optional} +#define @\defnlibxname{cpp_lib_optional}@ 202106L // also in \libheader{optional} #define @\defnlibxname{cpp_lib_out_ptr}@ 202106L // also in \libheader{memory} #define @\defnlibxname{cpp_lib_parallel_algorithm}@ 201603L // also in \libheader{algorithm}, \libheader{numeric} #define @\defnlibxname{cpp_lib_polymorphic_allocator}@ 201902L // also in \libheader{memory_resource} @@ -701,7 +701,7 @@ #define @\defnlibxname{cpp_lib_uncaught_exceptions}@ 201411L // also in \libheader{exception} #define @\defnlibxname{cpp_lib_unordered_map_try_emplace}@ 201411L // also in \libheader{unordered_map} #define @\defnlibxname{cpp_lib_unwrap_ref}@ 201811L // also in \libheader{type_traits} -#define @\defnlibxname{cpp_lib_variant}@ 202102L // also in \libheader{variant} +#define @\defnlibxname{cpp_lib_variant}@ 202106L // also in \libheader{variant} #define @\defnlibxname{cpp_lib_void_t}@ 201411L // also in \libheader{type_traits} \end{codeblock} diff --git a/source/utilities.tex b/source/utilities.tex index d2e8e155eb..15f7993404 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -2442,7 +2442,7 @@ // \ref{optional.specalg}, specialized algorithms template - void swap(optional&, optional&) noexcept(@\seebelow@); + constexpr void swap(optional&, optional&) noexcept(@\seebelow@); template constexpr optional<@\seebelow@> make_optional(T&&); @@ -2482,25 +2482,25 @@ template constexpr explicit(@\seebelow@) optional(U&&); template - explicit(@\seebelow@) optional(const optional&); + constexpr explicit(@\seebelow@) optional(const optional&); template - explicit(@\seebelow@) optional(optional&&); + constexpr explicit(@\seebelow@) optional(optional&&); // \ref{optional.dtor}, destructor - ~optional(); + constexpr ~optional(); // \ref{optional.assign}, assignment - optional& operator=(nullopt_t) noexcept; + constexpr optional& operator=(nullopt_t) noexcept; constexpr optional& operator=(const optional&); constexpr optional& operator=(optional&&) noexcept(@\seebelow@); - template optional& operator=(U&&); - template optional& operator=(const optional&); - template optional& operator=(optional&&); - template T& emplace(Args&&...); - template T& emplace(initializer_list, Args&&...); + template constexpr optional& operator=(U&&); + template constexpr optional& operator=(const optional&); + template constexpr optional& operator=(optional&&); + template constexpr T& emplace(Args&&...); + template constexpr T& emplace(initializer_list, Args&&...); // \ref{optional.swap}, swap - void swap(optional&) noexcept(@\seebelow@); + constexpr void swap(optional&) noexcept(@\seebelow@); // \ref{optional.observe}, observers constexpr const T* operator->() const; @@ -2519,7 +2519,7 @@ template constexpr T value_or(U&&) &&; // \ref{optional.mod}, modifiers - void reset() noexcept; + constexpr void reset() noexcept; private: T *val; // \expos @@ -2719,7 +2719,7 @@ \indexlibraryctor{optional}% \begin{itemdecl} -template explicit(@\seebelow@) optional(const optional& rhs); +template constexpr explicit(@\seebelow@) optional(const optional& rhs); \end{itemdecl} \begin{itemdescr} @@ -2761,7 +2761,7 @@ \indexlibraryctor{optional}% \begin{itemdecl} -template explicit(@\seebelow@) optional(optional&& rhs); +template constexpr explicit(@\seebelow@) optional(optional&& rhs); \end{itemdecl} \begin{itemdescr} @@ -2806,7 +2806,7 @@ \indexlibrarydtor{optional}% \begin{itemdecl} -~optional(); +constexpr ~optional(); \end{itemdecl} \begin{itemdescr} @@ -2826,7 +2826,7 @@ \indexlibrarymember{operator=}{optional}% \begin{itemdecl} -optional& operator=(nullopt_t) noexcept; +constexpr optional& operator=(nullopt_t) noexcept; \end{itemdecl} \begin{itemdescr} @@ -2947,7 +2947,7 @@ \indexlibrarymember{operator=}{optional}% \begin{itemdecl} -template optional& operator=(U&& v); +template constexpr optional& operator=(U&& v); \end{itemdecl} \begin{itemdescr} @@ -2977,7 +2977,7 @@ \indexlibrarymember{operator=}{optional}% \begin{itemdecl} -template optional& operator=(const optional& rhs); +template constexpr optional& operator=(const optional& rhs); \end{itemdecl} \begin{itemdescr} @@ -3040,7 +3040,7 @@ \indexlibrarymember{operator=}{optional}% \begin{itemdecl} -template optional& operator=(optional&& rhs); +template constexpr optional& operator=(optional&& rhs); \end{itemdecl} \begin{itemdescr} @@ -3104,7 +3104,7 @@ \indexlibrarymember{emplace}{optional}% \begin{itemdecl} -template T& emplace(Args&&... args); +template constexpr T& emplace(Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -3135,7 +3135,7 @@ \indexlibrarymember{emplace}{optional}% \begin{itemdecl} -template T& emplace(initializer_list il, Args&&... args); +template constexpr T& emplace(initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -3168,7 +3168,7 @@ \indexlibrarymember{swap}{optional}% \begin{itemdecl} -void swap(optional& rhs) noexcept(@\seebelow@); +constexpr void swap(optional& rhs) noexcept(@\seebelow@); \end{itemdecl} \begin{itemdescr} @@ -3389,7 +3389,7 @@ \indexlibrarymember{reset}{optional}% \begin{itemdecl} -void reset() noexcept; +constexpr void reset() noexcept; \end{itemdecl} \begin{itemdescr} @@ -3848,7 +3848,8 @@ \indexlibrarymember{swap}{optional}% \begin{itemdecl} -template void swap(optional& x, optional& y) noexcept(noexcept(x.swap(y))); +template + constexpr void swap(optional& x, optional& y) noexcept(noexcept(x.swap(y))); \end{itemdecl} \begin{itemdescr} @@ -4024,7 +4025,7 @@ // \ref{variant.specalg}, specialized algorithms template - void swap(variant&, variant&) noexcept(@\seebelow@); + constexpr void swap(variant&, variant&) noexcept(@\seebelow@); // \ref{variant.bad.access}, class \tcode{bad_variant_access} class bad_variant_access; @@ -4065,30 +4066,31 @@ constexpr explicit variant(in_place_index_t, initializer_list, Args&&...); // \ref{variant.dtor}, destructor - ~variant(); + constepxr ~variant(); // \ref{variant.assign}, assignment constexpr variant& operator=(const variant&); constexpr variant& operator=(variant&&) noexcept(@\seebelow@); - template variant& operator=(T&&) noexcept(@\seebelow@); + template constexpr variant& operator=(T&&) noexcept(@\seebelow@); // \ref{variant.mod}, modifiers template - T& emplace(Args&&...); + constexpr T& emplace(Args&&...); template - T& emplace(initializer_list, Args&&...); + constexpr T& emplace(initializer_list, Args&&...); template - variant_alternative_t>& emplace(Args&&...); + constexpr variant_alternative_t>& emplace(Args&&...); template - variant_alternative_t>& emplace(initializer_list, Args&&...); + constexpr variant_alternative_t>& + emplace(initializer_list, Args&&...); // \ref{variant.status}, value status constexpr bool valueless_by_exception() const noexcept; constexpr size_t index() const noexcept; // \ref{variant.swap}, swap - void swap(variant&) noexcept(@\seebelow@); + constexpr void swap(variant&) noexcept(@\seebelow@); }; } \end{codeblock} @@ -4414,7 +4416,7 @@ \indexlibrarydtor{variant}% \begin{itemdecl} -~variant(); +constexpr ~variant(); \end{itemdecl} \begin{itemdescr} @@ -4533,7 +4535,7 @@ \indexlibrarymember{operator=}{variant}% \begin{itemdecl} -template variant& operator=(T&& t) noexcept(@\seebelow@); +template constexpr variant& operator=(T&& t) noexcept(@\seebelow@); \end{itemdecl} \begin{itemdescr} @@ -4615,7 +4617,7 @@ \indexlibrarymember{emplace}{variant}% \begin{itemdecl} -template T& emplace(Args&&... args); +template constexpr T& emplace(Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -4635,7 +4637,8 @@ \indexlibrarymember{emplace}{variant}% \begin{itemdecl} -template T& emplace(initializer_list il, Args&&... args); +template + constexpr T& emplace(initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} @@ -4656,7 +4659,7 @@ \indexlibrarymember{emplace}{variant}% \begin{itemdecl} template - variant_alternative_t>& emplace(Args&&... args); + constexpr variant_alternative_t>& emplace(Args&&... args); \end{itemdecl} \begin{itemdescr} % NOCHECK: order @@ -4697,7 +4700,8 @@ \indexlibrarymember{emplace}{variant}% \begin{itemdecl} template - variant_alternative_t>& emplace(initializer_list il, Args&&... args); + constexpr variant_alternative_t>& + emplace(initializer_list il, Args&&... args); \end{itemdecl} \begin{itemdescr} % NOCHECK: order @@ -4778,7 +4782,7 @@ \indexlibrarymember{swap}{variant}% \begin{itemdecl} -void swap(variant& rhs) noexcept(@\seebelow@); +constexpr void swap(variant& rhs) noexcept(@\seebelow@); \end{itemdecl} \begin{itemdescr} @@ -5250,7 +5254,7 @@ \indexlibrarymember{swap}{variant}% \begin{itemdecl} template - void swap(variant& v, variant& w) noexcept(@\seebelow@); + constexpr void swap(variant& v, variant& w) noexcept(@\seebelow@); \end{itemdecl} \begin{itemdescr}